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 6677669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:09:01+00:00 2026-05-26T04:09:01+00:00

I currently have a stored procedure which returns data and displayed in my report

  • 0

I currently have a stored procedure which returns data and displayed in my report viewer but my issue is that i check to see if students attended to class or not and i have

COALESCE(A.Attended, 0)AS Attended

This returns 1 if they attended and 0 if not – in my report it only shows 1 or 0 even though they could have attended more than once. How can i cast this to an int to get the right total.

thanks

WHOLE QUERY:

SELECT 
    P.PartyId,
    COUNT(COALESCE(A.Attended, 0))AS Attended,
    COUNT(DISTINCT H.HearingId) AS Hearings,
    O.OfficeName As OfficeName,
    CO.Name,
    P.FirstName AS FirstName,
    P.LastName AS LastName,
    P.BirthDate AS DOB
FROM Activity A 
INNER JOIN ActivityType AT On A.ActivityTypeId = AT.ActivityTypeId
INNER JOIN ActivityEntry AE ON A.ActivityEntryId = AE.ActivityEntryId
INNER JOIN HearingEntry HE ON CAE.HearingEntryId = HE.HearingEntryId
INNER JOIN Hearing H ON HE.HearingEntryId = H.HearingEntryId
INNER JOIN [Case] C ON H.CaseId = C.CaseId
INNER JOIN CaseOffice CO ON C.CaseId = CO.CaseId AND AE.OfficeId = CO.OfficeId
INNER JOIN Office O ON CO.OfficeId = O.OfficeId
INNER JOIN Attended A ON H.HearingId = A.HearingId
INNER JOIN Party P ON A.PartyId = P.PartyId
WHERE HP.PartyId = P.PartyId AND AE.OfficeId = @OfficeId AND(H.HearingDate >= @BeginDate AND (H.HearingDate <= @EndDate OR H.HearingDate IS NULL)) AND HE.HearingEntryId = CAE.HearingEntryId
GROUP BY P.PartyId, A.Attended, O.OfficeName,CO.Name,P.FirstName, P.LastName,P.BirthDate
  • 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-26T04:09:01+00:00Added an answer on May 26, 2026 at 4:09 am

    You need to SUM by Attended .

    SELECT 
        P.PartyId,
        (SUM(COALESCE(A.Attended, 0)))AS Attended,
        COUNT(DISTINCT H.HearingId) AS Hearings,
        O.OfficeName As OfficeName,
        CO.Name,
        P.FirstName AS FirstName,
        P.LastName AS LastName,
        P.BirthDate AS DOB
    FROM Activity A 
    INNER JOIN ActivityType AT On A.ActivityTypeId = AT.ActivityTypeId
    INNER JOIN ActivityEntry AE ON A.ActivityEntryId = AE.ActivityEntryId
    INNER JOIN HearingEntry HE ON CAE.HearingEntryId = HE.HearingEntryId
    INNER JOIN Hearing H ON HE.HearingEntryId = H.HearingEntryId
    INNER JOIN [Case] C ON H.CaseId = C.CaseId
    INNER JOIN CaseOffice CO ON C.CaseId = CO.CaseId AND AE.OfficeId = CO.OfficeId
    INNER JOIN Office O ON CO.OfficeId = O.OfficeId
    INNER JOIN Attended A ON H.HearingId = A.HearingId
    INNER JOIN Party P ON A.PartyId = P.PartyId
    WHERE HP.PartyId = P.PartyId AND AE.OfficeId = @OfficeId AND(H.HearingDate >= @BeginDate AND (H.HearingDate <= @EndDate OR H.HearingDate IS NULL)) AND HE.HearingEntryId = CAE.HearingEntryId
    GROUP BY P.PartyId, O.OfficeName,CO.Name,P.FirstName, P.LastName,P.BirthDate
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a stored procedure in SQL Server that returns some data via a
I have a stored procedure which always returns a single row Currently my code
I have a stored procedure currently executing a complicated fetch that is frequently timing
I have a stored procedure which returns all the fields of a table plus
Helo, My question is I have one Stored Procedure in SQL Server that returns
I have a stored procedure that, depending on the input, returns multiple rows of
I have a stored procedure that adds an object to the database and returns
We currently have an application that depends largely on stored procedures. There is a
I have a database with DateTime fields that are currently stored in local time.
I have a stored procedure which selects a single field from a single row

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.