Discussion Locked

SQL2000-Passing in a where clause?

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I am trying to pass in a 'where' clause to a stored procedure. This 'where' clause will be different every time. I am trying to hide my logic in the stored procedure rather than pass back a record set and then use my logic on the results. I cannot get SQL to recognize the input parameter as part of the stored procedure. Is this even possible? If so what is the trick? Thanks!!

1 reply

by robertwierdsma

Build the Select statement into a string variable and then use exec (strvar)
e.g.

select @cmd = 'select col1, col2 from table1 '
+ @WhereParamStr + ' other SQL stuff if you need it'

exec (@cmd)

Go to http://www.swynk.com/ and see the sqlscripts section for lots of examples.

This discussion is closed to new replies.