I have the following stored procedure code working and want to add the passed parameter @tabname as a column in the result set.
CREATE PROCEDURE CountStar
@Tabname char(10)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @SQL varchar(250)
SELECT @SQL = 'SELECT ETL_LAST_UPD_DTTM, COUNT(*) FROM ls.' + QuoteName(@Tabname) +
'GROUP BY ETL_LAST_UPD_DTTM'
EXEC (@SQL)
SELECT @SQL = 'SELECT ETL_LAST_UPD_DTTM, COUNT(*) FROM ci.' + QuoteName(@Tabname) +
'GROUP BY ETL_LAST_UPD_DTTM'
EXEC (@SQL)
--COMMIT
END
GO
Currently this will return the last updated timestamp and the record count for the table being passed into the stored procedure for the 2 schemas identified. I want to add the @tabname to the result set as the first column followed by last updated timestamp and the record counts. This returns 2 result sets and each should look something like this for each returned result set.
Table_name Timestamp rec_cnt
--------------------------------------------------
CUSTOMERS 2015-09-24 13:10:01.1770000 378
I have tried a few things but can't get the syntax correct.
Thanks for any pointers. Pat
' Group By...'