Quote Originally Posted by szlamany
And what is making you think that the CURSOR can be set to a variable string of SQL?

I did this and it worked

Code:
declare c cursor for select * from tcs_t
deallocate c
But this gets a syntax error

Code:
declare @str varchar(100)
set @str='select * from tcs_t'
declare c cursor for @str
deallocate c
You will have to change your logic so that the WHERE clause has OR's and what not...
Learn something new every day!

Also, your if conditions don't append an 'AND' or 'OR' so that won't work as a regular query anyways... I think.