Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6245663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:32:47+00:00 2026-05-24T12:32:47+00:00

Within my application, I have a set of filters that can be applied when

  • 0

Within my application, I have a set of filters that can be applied when listing resources, which builds up a query by adding WHERE clauses, etc. before executing the query. This is using SQL Server 2008.

I have two pertinent tables, one which contains some static data about the resource, and another which can contain arbitrary/optional fields pertaining to that resource.

First table is something like this (table names & fields changed):

CREATE TABLE Resources (
    ResID       varbinary(28),

    ... extra stuff omitted

    type        integer );

The second table just has name/value pairs and the corresponding resource ID

CREATE TABLE ResourceFields (
    ResID       varbinary(28) NOT NULL,

    Name        nvarchar(255) NOT NULL,
    Value       nvarchar(1024) NOT NULL);

So, for this example, there could be multiple rows in ‘ResourceFields’ with name = ‘ContactName’ for the same ResID.

What I want to do is get a count of the number of rows in the ‘Resources’ table that have more than one ‘ContactName’ listed in ‘ResourceFields’ with ‘type’ equal to some value.

I came up with this (don’t laugh — I know just enough SQL to cause problems)

SELECT count(r.ResID) 
    FROM Resources as r 
        INNER JOIN ResourceFields AS rf 
            ON rf.ResID = r.ResID 
                AND rf.name = 'ContactName' 
    WHERE r.type = 1 
    GROUP BY rf.ResID 
    HAVING COUNT(rf.Value) > 1;

but instead of returning the count of the number of rows (43 in my test set) in ‘Resources’, I get all the COUNT(rf.Value) values returned (that is, 43 individual counts).

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:32:47+00:00Added an answer on May 24, 2026 at 12:32 pm

    Just use your original query as a derived table (put it in a subselect):

    SELECT COUNT(*)
    FROM (
        SELECT count(*) AS C
        FROM Resources as r 
            INNER JOIN ResourceFields AS rf 
                ON rf.ResID = r.ResID 
                    AND rf.name = 'ContactName' 
        WHERE r.type = 1 
        GROUP BY rf.ResID 
        HAVING COUNT(rf.Value) > 1;
    ) s
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Within my iPhone application I have a common tab bar with three tabs that
I have a Web page within my application that needs to call a web
I execute some tests within my application, but before doing that I have to
I have an application that is launched from within a service using a local
I have an application that creates user notifications when various things happen within the
Within my application I have a process which takes some time (30s - 5mins)
I am implementing instrumentation within an application and have encountered an issue where the
We have issues within an application using a state machine. The application is implemented
I have access to a 3rd party PropertyGrid within my application (C#. ,Net v2).
Thanks in advance for your help. I have a need within an application to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.