EugenePaliev
Programmer
Hello all!
There are two things I want to do:
1) to know number of records
2) set this number into variable.
It works if I do something like this
But I need to build my sql statement dinamicly. I use sp_executesql to accomplish this. So I try next
and it doesn't wotk... "Incorrect syntax near the keyword 'execute'."
Is there a way to dynamicly execute sql (with sp_executesql) and set returned value into variable?
Any help would be greatly appreciated!!
Thanks in advance. Good Luck!
There are two things I want to do:
1) to know number of records
2) set this number into variable.
It works if I do something like this
Code:
declare @rows int
set @rows = (select count(column_name) from table where column_name2=x)
But I need to build my sql statement dinamicly. I use sp_executesql to accomplish this. So I try next
Code:
declare @rows int
declare @sql nvarchar(1000)
set @sql = N'some select statement here ... '
set rows = (execute sp_executesql @statement)
and it doesn't wotk... "Incorrect syntax near the keyword 'execute'."
Is there a way to dynamicly execute sql (with sp_executesql) and set returned value into variable?
Any help would be greatly appreciated!!
Thanks in advance. Good Luck!