I have an SSRS report which creates a multi-page report of Customer IDs and their associated batch codes.
I achieve this by logging the Customer IDs that have been sent in a "Sent" table, then left joining on that to exclude IDs that have already been sent.
Page 1 comes from one stored procedure, Page 2 comes from another.
Stored Proc 1 / Page 1 is a select of customer accounts, including batch code, which have not already been selected, then the stored proc logs those details to the sent table:
--Select new records for report into temp table
SELECT a.CustomerID,
a.BatchCode
INTO #CustomersToSend
FROM dbo.CustomerBatches a
LEFT JOIN dbo.Sent b ON a.CustomerID = b.CustomerID
WHERE b.SentDate IS NULL
--Insert these records into the sent table
INSERT INTO dbo.Sent
SELECT CustomerID,
GETDATE() AS SentDate
FROM #CustomersToSend
--Select the temp table to produce the report output
SELECT *
FROM #CustomersToSend
Stored Proc 2 needs to be a summary of batch codes contained in Page 1:
--Batch Summary
SELECT BatchCode,
COUNT(*) AS TotalCustomers
FROM dbo.CustomerBatches
GROUP BY BatchCode
I need to fiter this query in the same way as I filtered the first one, excluding any CustomerIDs that have already been sent.
My problem is I don't know how SSRS handles this type of report.
If it runs stored proc 1, waits for it to finish, then runs stored proc 2, then fine, I can use the SentDate in dbo.Sent to filter on CustomerIDs sent in the last few seconds.
If it runs both stored proc 1 and 2 at the same time, then I could possibly use the same logic as Stored Proc 1, a left join onto dbo.Sent in order to exclude sent CustomerIDs. I'm not sure what would happen if stored proc 2 was running at the very moment that stored proc 1 was trying to write to dbo.Sent however...
Ideally, I would have it run stored proc 2 first, wait for it to finish, then run stored proc 1. But my output from stored proc 1 must be page 1 of the report. I figure if it does run them in serial rather than in parallel, then it would go in page order?
Any help / insight would be appreciated.
I suggest to use only one dataset. You can re-use your first dataset in a summary table on the second page, grouping the records in that table by BatchCode
and letting SSRS do the counting.