Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Dynamic Where Clause In Stored Procedure
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00634614
Message ID:
00640046
Vues:
31
>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform