I have this query:
DECLARE @selectsql nvarchar(4000),
DECLARE @cnt int
select @selectsql = ' SELECT ' + @cnt + '= COUNT(*) FROM Vwbckup'
print @selectsql
print @cnt
EXEC sp_executesql @selectsql
When I execute the query I’m getting this error:
Conversion failed when converting the varchar value ‘ SELECT ‘ to data type int.
You don’t apparently need dynamic SQL for this but in case you do for some reason not shown you don’t need to concatenate that part at all. You can use an
OUTPUTparameter.