Link to home
Start Free TrialLog in
Avatar of dentyne
dentyne

asked on

Query Help

Greetings:

I wanted to write a stored procedure that had somewhat of a dynamic query.  I wanted to pass it a string to be used in the "WHERE" clause. Here is a snippet of code to demonstrate my request:

CREATE PROCEDURE spTesting
    @Filter          varchar(255)
AS

SELECT      *
FROM     Table1
WHERE      @Filter

So for instance, if @Filter would be "FieldName1 = 'John'"; how would I do this?  So once the variable is passed the query would execute like the following:

SELECT  *
FROM    Table1
WHERE   FieldName1 = 'John'

Thanks!
-Jacob
ASKER CERTIFIED SOLUTION
Avatar of dmeili
dmeili

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dentyne
dentyne

ASKER

Great job man.  You're very knowledgeable.