I'm having a strange problem with a query that I hope someone may have seen before. I've declared a variable @statvar as type int and @cmd1 as a varchar (255).
The statement where I'm having the problem is as follows:
set @cmd1='select @statvar=count(*) from '+@dbname+'..sysfiles'
I keep getting the error "Must declare the variable @statvar"
I've worked around the problem by eliminating the '@statvar= ' and sending the results to a temp table instead, but I'm curious as to why the original query doesn't work. I don't have any 'go' statements prior to it.
Thanks in advance!