passing where clause to stored procedure as parameter

  • 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.

  • You already have another thread on this very topic.  Please do not start duplicate threads.  It fragments the discussion.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply