I want to pass an SQL command to a variable and execute aggregate function for that. but when I run it, this error is shown, and nothing appear for @cnt value ,
Must declare the variable '@cnt'
What's my mistake ?
DECLARE @ret varchar(300);
set @ret = '';
declare @cnt int;
set @ret = 'select @cnt = count(*) from TBL1'
EXEC (@ret)
print @cnt