Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Dynamic Where Clause In Stored Procedure
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00634614
Message ID:
00640046
Views:
30
>I'm not sure that I completely understand your question. Does "50 to 100 lines" translate to search arguments? If so, then sometimes you can work around things like that.

Mike,
I have about 10 or 20 fields that the user can query. The query is built by a VFP front end that allows the user to select fields and values to select from. For example:

SELECT COUNT(*) FROM myTable 
WHERE Field1 IN ( ('A','B','C','F','Y')
AND Field2 IN ('1','2','3')
AND SUBSTRING(Field5,1,1) = '1' )
OR (Field3 IN ('X','Y','Z') and State = 'NY')
OR Field4 = 'ABCDEFG'
I have no way of knowing ahead of time which fields will participate in the query. Frequently I have to OMIT other tables' values:
SELECT ...
WHERE ...
AND NOT Email IN (SELECT Email FROM #tmp1)
AND Zip IN (SELECT Zip FROM #tmp2)
The way I approach this (for lack of a better solution) is:
SET @lcSQLCmd = 'SELECT COUNT(*) 
FROM mytable
WHERE ' + @lcQueryString
EXEC(@lcQuery)

Where @lcQuery is a parameter passed to SQL fromVFP. Is there another way to do this?
Aristotle
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform