SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to call different results from stored procedure to SSRS report


How to call different results from stored procedure to SSRS report

Author
Message
mcfarlandparkway
mcfarlandparkway
SSC Eights!
SSC Eights! (805 reputation)SSC Eights! (805 reputation)SSC Eights! (805 reputation)SSC Eights! (805 reputation)SSC Eights! (805 reputation)SSC Eights! (805 reputation)SSC Eights! (805 reputation)SSC Eights! (805 reputation)

Group: General Forum Members
Points: 805 Visits: 729
Hello,
I am creating an SSRS report in that I want to create three fields

1.Subtotal
2.Grand total
3.Admin total


For this I created a stored procedure usp_SSRS_RSTotalDetailAmount

In this stored procedure I am getting results as

amount
3440.21
3492.93
68.21


These amount results I need to display in SSRS report like
In subtotal - 3440.21
Grand total - 3492.93
Admin total - 68.21


Problem is that for the same stored procedure with same field how can I display amounts in SSRS
lynns
lynns
SSC-Enthusiastic
SSC-Enthusiastic (141 reputation)SSC-Enthusiastic (141 reputation)SSC-Enthusiastic (141 reputation)SSC-Enthusiastic (141 reputation)SSC-Enthusiastic (141 reputation)SSC-Enthusiastic (141 reputation)SSC-Enthusiastic (141 reputation)SSC-Enthusiastic (141 reputation)

Group: General Forum Members
Points: 141 Visits: 323
Did you consider setting up the stored procedure to return a 3 field table, with fields Subtotal, GrandTotal, and AdminTotal?
mcfarlandparkway
mcfarlandparkway
SSC Eights!
SSC Eights! (805 reputation)SSC Eights! (805 reputation)SSC Eights! (805 reputation)SSC Eights! (805 reputation)SSC Eights! (805 reputation)SSC Eights! (805 reputation)SSC Eights! (805 reputation)SSC Eights! (805 reputation)

Group: General Forum Members
Points: 805 Visits: 729
No, I am not using those fields in my sp,if I use those its very easy to drag me in SSRS report but he problem is I am selecting only 'invoiceamnt' field

Below is my stored procedure..When I execute this sp results showing as like
invoiceamt
234.5
5677.654
344.6
but my expected output is like straight records as a single dataset I tried by renaming amounts as 1 and 2 but not sure its not working..

SELECT I.ReimbursementTypeID,
CAST (SUM(ISNULL(I.AMOUNT,0) - ISNULL(I.OtherAmount,0)) AS NUMERIC(18,2)) AS 'invoiceamt'
FROM grantsystem G
INNER JOIN request R on G.Grantsystemid = R.GrantSystemID
INNER JOIN invoice I on R.requestid = I.requestid
INNER JOIN vlookups L on I.Reimbursementtypeid = L.lookupid
INNER JOIN vSchool VS on G.SystemID = VS.SystemID AND I.SchoolID = VS.SchoolID
WHERE G.fiscalyear=@FiscalYear AND G.SystemID = @SystemId AND I.ReimbursementTypeID IN(34,35) AND
I.SchoolID=Case When @SchoolId ='0' Then I.SchoolID Else @SchoolId End AND
MONTH(R.FundMonth)=Case When @FundMonth='0' Then MONTH(R.FundMonth) Else CONVERT(INT,@FundMonth) End
AND (I.IsActive=1) AND (R.IsActive=1) AND (G.IsActive=1)
GROUP BY fiscalyear, G.SystemID,I.ReimbursementTypeID

UNION ALL

SELECT I.ReimbursementTypeID,
CAST (SUM(ISNULL(I.AMOUNT,0) - ISNULL(I.OtherAmount,0)) AS NUMERIC(18,2)) AS 'invoiceamt'
FROM grantsystem G
INNER JOIN request R on G.Grantsystemid = R.GrantSystemID
INNER JOIN invoice I on R.requestid = I.requestid
INNER JOIN vlookups L on I.Reimbursementtypeid = L.lookupid
INNER JOIN vSchool VS on G.SystemID = VS.SystemID AND I.SchoolID = VS.SchoolID
WHERE G.fiscalyear=@FiscalYear AND G.SystemID = @SystemId AND I.ReimbursementTypeID IN(34,35,36) AND
I.SchoolID=Case When @SchoolId ='0' Then I.SchoolID Else @SchoolId End AND
MONTH(R.FundMonth)=Case When @FundMonth='0' Then MONTH(R.FundMonth) Else CONVERT(INT,@FundMonth) End
AND (I.IsActive=1) AND (R.IsActive=1) AND (G.IsActive=1)
GROUP BY fiscalyear, G.SystemID,I.ReimbursementTypeID

UNION ALL

SELECT I.ReimbursementTypeID,
CAST (SUM(ISNULL(I.AMOUNT,0) - ISNULL(I.OtherAmount,0)) AS NUMERIC(18,2)) AS 'invoiceamt'
FROM grantsystem G
INNER JOIN request R on G.Grantsystemid = R.GrantSystemID
INNER JOIN invoice I on R.requestid = I.requestid
INNER JOIN vlookups L on I.Reimbursementtypeid = L.lookupid
INNER JOIN vSchool VS on G.SystemID = VS.SystemID AND I.SchoolID = VS.SchoolID
WHERE G.fiscalyear=@FiscalYear AND G.SystemID = @SystemId AND I.ReimbursementTypeID IN(37,38,53) AND
I.SchoolID=Case When @SchoolId ='0' Then I.SchoolID Else @SchoolId End AND
MONTH(R.FundMonth)=Case When @FundMonth='0' Then MONTH(R.FundMonth) Else CONVERT(INT,@FundMonth) End
AND (I.IsActive=1) AND (R.IsActive=1) AND (G.IsActive=1)
GROUP BY fiscalyear, G.SystemID,I.ReimbursementTypeID

END
doug.brown
doug.brown
SSChasing Mays
SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)

Group: General Forum Members
Points: 651 Visits: 14059
If I'm understanding the problem correctly, you might be able to get the field names in your procedure by using joins instead of unions:


SELECT
sub.invoiceamt as Subtotal
grand.invoiceamt as GrandTotal
admin.invoiceamt as AdminTotal
FROM
(
SELECT I.ReimbursementTypeID,
CAST (SUM(ISNULL(I.AMOUNT,0) - ISNULL(I.OtherAmount,0)) AS NUMERIC(18,2)) AS 'invoiceamt'
FROM grantsystem G
INNER JOIN request R on G.Grantsystemid = R.GrantSystemID
INNER JOIN invoice I on R.requestid = I.requestid
INNER JOIN vlookups L on I.Reimbursementtypeid = L.lookupid
INNER JOIN vSchool VS on G.SystemID = VS.SystemID AND I.SchoolID = VS.SchoolID
WHERE G.fiscalyear=@FiscalYear AND G.SystemID = @SystemId AND I.ReimbursementTypeID IN(34,35) AND
I.SchoolID=Case When @SchoolId ='0' Then I.SchoolID Else @SchoolId End AND
MONTH(R.FundMonth)=Case When @FundMonth='0' Then MONTH(R.FundMonth) Else CONVERT(INT,@FundMonth) End
AND (I.IsActive=1) AND (R.IsActive=1) AND (G.IsActive=1)
GROUP BY fiscalyear, G.SystemID,I.ReimbursementTypeID
) as sub

JOIN

(
SELECT I.ReimbursementTypeID,
CAST (SUM(ISNULL(I.AMOUNT,0) - ISNULL(I.OtherAmount,0)) AS NUMERIC(18,2)) AS 'invoiceamt'
FROM grantsystem G
INNER JOIN request R on G.Grantsystemid = R.GrantSystemID
INNER JOIN invoice I on R.requestid = I.requestid
INNER JOIN vlookups L on I.Reimbursementtypeid = L.lookupid
INNER JOIN vSchool VS on G.SystemID = VS.SystemID AND I.SchoolID = VS.SchoolID
WHERE G.fiscalyear=@FiscalYear AND G.SystemID = @SystemId AND I.ReimbursementTypeID IN(34,35,36) AND
I.SchoolID=Case When @SchoolId ='0' Then I.SchoolID Else @SchoolId End AND
MONTH(R.FundMonth)=Case When @FundMonth='0' Then MONTH(R.FundMonth) Else CONVERT(INT,@FundMonth) End
AND (I.IsActive=1) AND (R.IsActive=1) AND (G.IsActive=1)
GROUP BY fiscalyear, G.SystemID,I.ReimbursementTypeID
) as grand

JOIN

(
SELECT I.ReimbursementTypeID,
CAST (SUM(ISNULL(I.AMOUNT,0) - ISNULL(I.OtherAmount,0)) AS NUMERIC(18,2)) AS 'invoiceamt'
FROM grantsystem G
INNER JOIN request R on G.Grantsystemid = R.GrantSystemID
INNER JOIN invoice I on R.requestid = I.requestid
INNER JOIN vlookups L on I.Reimbursementtypeid = L.lookupid
INNER JOIN vSchool VS on G.SystemID = VS.SystemID AND I.SchoolID = VS.SchoolID
WHERE G.fiscalyear=@FiscalYear AND G.SystemID = @SystemId AND I.ReimbursementTypeID IN(37,38,53) AND
I.SchoolID=Case When @SchoolId ='0' Then I.SchoolID Else @SchoolId End AND
MONTH(R.FundMonth)=Case When @FundMonth='0' Then MONTH(R.FundMonth) Else CONVERT(INT,@FundMonth) End
AND (I.IsActive=1) AND (R.IsActive=1) AND (G.IsActive=1)
GROUP BY fiscalyear, G.SystemID,I.ReimbursementTypeID
) as admin


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search