How to use If Statement in Where Clause in SQL?

后端 未结 4 449
抹茶落季
抹茶落季 2020-12-17 16:12

I need to use if statement inside where clause in sql.

Select * from Customer
WHERE  (I.IsClose=@ISClose OR @ISClose is NULL)  
AND    
(C.FirstName like \'%         


        
4条回答
  •  遥遥无期
    2020-12-17 16:37

    Nto sure which RDBMS you are using, but if it is SQL Server you could look at rather using a CASE statement

    Evaluates a list of conditions and returns one of multiple possible result expressions.

    The CASE expression has two formats:

    The simple CASE expression compares an expression to a set of simple expressions to determine the result.

    The searched CASE expression evaluates a set of Boolean expressions to determine the result.

    Both formats support an optional ELSE argument.

提交回复
热议问题