Click to See Complete Forum and Search --> : Dynamic SQL Where clause


Webskater
08-21-2003, 09:38 AM
This is really a SQL question but I cannot see a SQL forum - and I guess if you're using ASP you are probably using a SQL database of some sort.
Anyway ... I need to create a dynamic Where clause within a Stored Procedure.
I might want to say ... WHERE ProductID = 3
or WHERE ProductID = 3 or ProductID=7 or ProductID = 9
etc.
The amount of parameters in the Where clause will vary. I can concatenate the clause until I am blue in the face but it will not execute. Any ideas how to do this.
Thanks.

rdoekes
08-21-2003, 02:56 PM
You can start by using the IN clause:
WHERE productID IN (3)
WHERE productID IN (3,5,7)

-Rogier Doekes

Webskater
08-21-2003, 05:05 PM
Thanks for your reply. I'm afraid I did not describe my query correctly. What I want to do is a Knowledge Base search. So I want to pass any keywords entered by a user into a Stored Procedure so that what I am effectively saying is:

WHERE Word1 OR Word2 or Word 3 (etc.) is in the SearchedField

or even

WHERE Word1 AND Word2 AND Word 3 (etc.) is in the SearchedField

Thanks for any help.