declare @strSQL nvarchar(2000)
declare @cnt int
SET @strSQL = ‘SELECT @cnt = count(*) FROM table1 WHERE field1 = 1’
Exec sp_sqlexec @strSQL, N’@cnt int ouput’, @cnt out
select @cnt as TestCount
declare @cnt int
SET @strSQL = ‘SELECT @cnt = count(*) FROM table1 WHERE field1 = 1’
Exec sp_sqlexec @strSQL, N’@cnt int ouput’, @cnt out
select @cnt as TestCount
or
declare @strSQL varchar(500) , @cnt int
create table #tmp ( cnt int)
SET @strSQL = ‘INSERT #tmp ‘SELECT count(*) FROM table1 WHERE field1 = 1”
exec (@strSQL)
select @cnt = cnt from #tmp
— to view the variable (for testing)
select @cnt as Counter
create table #tmp ( cnt int)
SET @strSQL = ‘INSERT #tmp ‘SELECT count(*) FROM table1 WHERE field1 = 1”
exec (@strSQL)
select @cnt = cnt from #tmp
— to view the variable (for testing)
select @cnt as Counter