Wednesday, July 31, 2013
T-SQL - Get RowCount from a Dynamically Executed Statement
DECLARE
@Period VARCHAR (8) = ''
, @DEDFYXXRecords BIGINT = 0
, @EXECFYXX NVARCHAR (MAX) = ''
, @RowCount BIGINT = 0;
SELECT @EXECFYXX = ' INSERT Data( '
+ ' Period '
+ ', CostCenter '
+ ') '
+ 'SELECT '
+ ' FYXX.Period '
+ ', FYXX.CostCenter '
+ 'FROM DataFY'
+ LEFT (@Period, 2)
+ ' FYXX '
+ ' JOIN DataB da '
+ ' ON FYXX.Account = da.Acct '
+ ' WHERE da.GroupID = 99 '
+ ' AND FYXX.Period = '''
+ @Period
+ '''; SELECT @RowCount = @@ROWCOUNT; ';
EXEC sp_executesql @EXECFYXX, N'@RowCount BIGINT OUTPUT', @RowCount OUTPUT
SELECT @DEDFYXXRecords = @RowCount
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment