Hello,
Can a where clause be inserted into a select statement as a variable?
For example, can I do this:
DECLARE @WhereClause nvarchar(max)
SET @WhereClause = 'WHERE (col1 like \'%abc%\' AND col2 like \'%xyz%\') OR (col3 like \'%abc%\' AND col4 like \'%xyz%\')'
SELECT * FROM MyTable @WhereClause
The reason I want to do this is that we want to send a set of search criteria from our application to a stored procedure. The application will parse the search criteria into a SQL WHERE clause and then pass that as a parameter to the stored procedure. In the stored procedure, I want to simply plop the parameter into the SELECT query.
Can this be done, or are there any alternatives that don't require drastically more work?
Thanks.