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

  • SEARCH
  • Home
  • 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 5987033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:45:24+00:00 2026-05-22T22:45:24+00:00

I have a query which returns some rows. Its column names are like: Age,

  • 0

I have a query which returns some rows. Its column names are like: Age, Gender, DOB etc. What I have to do is, to check how many rows are coming from DB of which Age.

E.g. see the image:

enter image description here

See the age subtotal, it means my query is returning 54 rows of age 0, 1 row of age 1 and so on.

This table of subtotal must display only those ages that are returned by the query. For example there is no Age 2 as it was not returned by query.

How can I sort this issue?

Edit

Here is my Stored Procedure:

ALTER PROCEDURE [dbo].[spGetClients]
(
    @orderBy varchar(50),
    @startAge int,
    @endAge int,
    @sex varchar(5),
    @developmentalDisability varchar(200),
    @staffId nvarchar(1024), 
    @statusId nvarchar(1024), 
    @ethnicityId nvarchar(1024), 
    @treatmentProviderId nvarchar(1024)
)

AS
BEGIN
    SET NOCOUNT ON;
    
        SELECT c.Id, dbo.GetClientFullName(c.FirstName, c.MiddleInit, c.LastName) AS ClientName, 
        c.DateOfBirth, dbo.GetAge(c.DateOfBirth, GETDATE()) AS Age, c.Sex, 
        dbo.GetClientStatus(c.Id, @statusId) AS Status, ca.Address, co.Phone, 
        dbo.GetEthnicity(c.Id, @ethnicityId) AS Ethnicity, dbo.GetDevelopmentalDisabilities(c.Id, @developmentalDisability) AS Disabilities, 
        dbo.GetClientStaffContacts(c.Id, @staffId) AS Staff, dbo.GetClientContacts(c.Id) AS Contact, 
        dbo.GetClientInsuranceProviders(c.Id) AS HealthProvider, 
        dbo.GetClientTreatmentProviders(c.Id, @treatmentProviderId) AS TreatmentProvider
        FROM Client c  
        LEFT OUTER JOIN(        
            SELECT ca.ParentEntityId, ca.Address
            FROM ContactAddress ca
            INNER JOIN EntityName en ON en.Id = ca.EntityNameId AND en.Name = 'Client' 
            INNER JOIN GeneralLookup gl ON ca.glAddressTypeId = gl.Id AND gl.LookupItem = 'Primary'    
        ) ca ON c.Id = ca.ParentEntityId 
        LEFT OUTER JOIN(        
            SELECT co.ParentEntityId, co.ContactData Phone
            FROM ContactOther co
            INNER JOIN EntityName en ON en.Id = co.EntityNameId AND en.Name = 'Client' 
            INNER JOIN GeneralLookup gl ON co.glContactTypeId = gl.Id AND gl.LookupItem = 'Home'    
        ) co ON c.Id = co.ParentEntityId 
        LEFT OUTER JOIN GeneralStatus gs on gs.Id = c.StatusId
        where gs.Name <> 'Deleted' 
        and (dbo.GetAge(c.DateOfBirth, GETDATE()) BETWEEN @startAge and @endAge)
        and ((@sex = 'M' and c.sex = 'M') or (@sex = 'F' and c.Sex = 'F') or (@sex = 'Both' and (c.Sex in ('M', 'F', ''))))
        and ((@staffId = '') OR (dbo.GetClientStaffContacts(c.Id, @staffId) is not null))
        and ((@statusId = '') OR (dbo.GetClientStatus(c.Id, @statusId) is not null))
        and ((@ethnicityId = '') OR (dbo.GetEthnicity(c.Id, @ethnicityId) is not null))
        and ((@treatmentProviderId = '') OR (dbo.GetClientTreatmentProviders(c.Id, @treatmentProviderId) is not null))
        ORDER BY 
            CASE
                WHEN @orderBy = 'Consumer Name' THEN dbo.GetClientFullName(c.FirstName, c.MiddleInit, c.LastName) 
                WHEN @orderBy = 'Consumer Address' THEN ca.Address
            END
END
  • 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-22T22:45:25+00:00Added an answer on May 22, 2026 at 10:45 pm

    Your query is pretty elaborate and the output seems to be for a report, couldn’t you just elaborate your sub-total in the report? (SSRS Tutorial for groups and totals)

    If it is not possible, i think you could modify your stored procedure to use a Table Variable: load the query in the table and then run the various subtotal query on it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Informix SQL query which returns a set of rows. It was
i've got a SQL query which returns multiple rows, and i have : $data
I have a Sql Query which returns me over half million rows to process...
I have a simple query which returns 25,026 rows: MySqlCommand cmd = new MySqlCommand(SELECT
I have a query which returns a series of cells of data from a
I have a linq query which returns the ID of a question based on
If I have a function which returns a reference cursor for a query, how
I have a query which is meant to show me any rows in table
I have a query which produces a list of orders like this: Invoice Description
I have a Linq query that returns an anonymous type, which I then use

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.