Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 executing a select stament as a variable

Author  Topic 

Mark
Starting Member

48 Posts

Posted - 2001-01-30 : 12:48:07
I have a variable that is created by a series of if statements:
@sql = 'select * from table where'
if @country <> '' (if country is not empty)
@sql = @sql + 'where country = ' + @country
if city <> ''
@sql = @sql + 'and city = '+@city

(not quite exactly... the statements to build are a little more complicated. )

I now have a @sql var that contains a statement. is it possible to execute this var as a statement?

execute @sql maybe?


any comments will help

   

- Advertisement -