adding filter conditions dynamically in WHERE clause -dynamic SQL help
611859Mar 7 2008 — edited Mar 7 2008Here I have a simple condition but very complicated query. Basically, I have to put a filter condition in my where clause. "Location" comes to the stored procedure as parameter. Plus there are other parameters as well.
If location = "all", I can run the query simply and get the result. But when Location = "CA", which is just a subset of "ALL" then I am having hard time putting one -- AND statement in WHERE clause.
This query is designed for location = 'ALL'
open cv for
'Select col1, col2, col3, Col4
from t1, t2, t3
WHERE condition1
AND condition2
AND condition3'
AND location = location_id --- This should only run if location IS NOT ALL
I have written a dynamic query but it doesn't work for that part. Any ideas will be appreciated. Thanks,