Count records returned by stored procedure to store in DashBoard table

I have a series of processes (Step #1) I'm running each morning to push/pull data into SQL Server from a variety of different data sources.  Thanks to numerous responses here, those processes are working properly and get run normally at about 05:00 each morning.  I'm not using SSIS at the moment because of the amount of data manipulation I'm having to do to get it into the structure I need.

Some of the data from these sources is suspect (imagine that), where values don't match from the multiple sources or even from within different tables a single data source.  So I have a number of other stored procedures which I am using to identify values in records in these tables which need to be scrutinized and resolved.  Those stored procedures, and the Access forms I'm using to view them are working great.

What I want to do is immediately after these processes (step #1 above) are run, I want to run through all of these other SPs, count the number of records returned by each of those stored procedures, and update the RecCount field (int) in tbl_Dashboard.  This way, when the users come in, they can open the application to the Dashboard and immediately know where they need to focus their attention (without having to run the SPs at that time).

How would you go about this?  Could I put another field in the Dashboard table with the name of the stored procedure and simply run a cursor to loop through that table, building a dynamic SQL string that returns the number of records and updates the [RecCount] field in the same table?

One caveat, these SPs all have two parameters (@StartDate and @EndDate).  I would pass these parameter to this SP when it gets called.

I know how I would do this from Access, but since so much of the process is running in SQL Server, I would like to know how you experts might approach this.
LVL 50
Dale FyeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

John_VidmarCommented:
Place something similar in each stored-procedure where you want to capture audit info into tbl_Dashboard:
/*
**	declare local variables to capture system info
*/
DECLARE	@li_Error	int
,	@li_RowCount	int

/*
**	some insert/update/delete statement here
*/

-- capture system variables affected by above into local variables
SELECT	@li_Error = @@error, @li_RowCount = @@rowcount
IF @li_Error <> 0 BEGIN
-- do some error handling
END

/*
**	Populate tbl_Dashboard here using @li_RowCount
*/

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dale FyeAuthor Commented:
John,

All of these particular SPs are select queries  so, could I simply call another SP and pass it the name of the SP and the @@RowCount value?  Something like:
SELECT * FROM table1

exec df_Dashboard_Update 'Stored procedure #1',  @@RowCount

Open in new window

or will the exec line affect the records returned to Access when it calls the SP?
0
John_VidmarCommented:
System variables get reset by almost any statement, if your example were to work then you are relying on no other developer from adding a statement between your select-statement (which populates @@rowcount) and the following stored-procedure call (which uses the @@rowcount).  Safer to capture @@rowcount into a variable and pass that to df_Dashboard_Update.

Due to scoping issues, I highly doubt that calling a stored-procedure (which contains only a select-statement) would transfer the @@rowcount to the next stored-procedure, i.e., the following would NOT work:
exec 'StoredProcedure1'

exec df_Dashboard_Update 'StoredProcedure1',  @@RowCount

Open in new window

0
Dale FyeAuthor Commented:
Thanks for the input John.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.