I need to write stored procedure with dynamic where condition for filtering some records. The filter parameters are given by the front end application.
Thanks
Stored Procedure with dynamic where condition
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Jignesh TrivediRank #16 · 50.3K reputationPosted Jun 4, 2014, 11:59 PM EDT
Hi,
To do this, I think you have to write dynamic query.
like
Create proc Test
( @where varchar(max)
)
AS
BEGIN
declare @sql varchar(max)
set @sql = 'select * from tablename where ' + @where
exec(@sql)
END
also refer
http://www.codeproject.com/Articles/21234/Implementing-Dynamic-WHERE-Clause-in-Static-SQL
hope this will help you
Anupam SinghRank #643 · 3.7K reputationPosted Jun 5, 2014, 12:03 AM EDT
you can create procedure with parameter ex:
CREATE PROCEDURE GetAddress @City varchar(30)
You just need to change city in parameter.
in C# you can achieve this using:
Hope will help.