SQL Server 2008 - Conditional Query

Posted by Villager on Stack Overflow See other posts from Stack Overflow or by Villager
Published on 2010-05-05T12:43:12Z Indexed on 2010/05/05 12:48 UTC
Read the original article Hit count: 246

Filed under:

Hello,

SQL is not one of my strong suits. I have a SQL Server 2008 database. This database has a stored procedure that takes in eight int parameters. For the sake of keeping this question focused, I will use one of these parameters for reference:

@isActive int

Each of these int parameters will be -1, 0, or 1. -1 means "Unknown" or "Don't Care". Basically, I need to query a table such that if the int parameter is NOT -1, I need to consider it in my WHERE clause. Because there are eight int parameters, an IF-ELSE statement does not seem like a good idea. At the same time, I do not know how else to do this?

Is there an elegant way in SQL to add a WHERE conditional if a parameter does NOT equal a value?

Thank you!

© Stack Overflow or respective owner

Related posts about sql