Link to home
Start Free TrialLog in
Avatar of CipherIS
CipherISFlag for United States of America

asked on

SQL - Dynamically build where clause

I wrote inline SQL in a C# .NET application but it is timing out so I am creating a SPROC in sql server.  

I need to pass in a parameter for the purpose of dynamically determining the where clause.  Any idea how to do this?

As an example - lets say I am passing in CheckDate as BIT, dtStart and dtEnd.

If CheckDate = 0 then

    Where MyDate > '1/1/13'

if CheckDate = 1 and the dtStart = '5/1/13' and dtEnd IS NULL

    Where MyDate >= '5/1/13'

if CheckDate = 1 and the dtStart = '5/1/13' and dtEnd = '5/31/13'

    Where MyDate >= '5/1/13' and MyDate <= '6/1/13'

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

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 CipherIS

ASKER

Awesome!  Thanks
Thanks for the grade.  Good luck with your project.  -Jim