Conditional WHERE clause in SQL Server

后端 未结 6 1567
猫巷女王i
猫巷女王i 2020-11-22 12:43

I am creating a SQL query in which I need a conditional where clause.

It should be something like this:

SELECT 
    DateAppr,
    Time         


        
6条回答
  •  眼角桃花
    2020-11-22 12:47

    Try this

    SELECT 
        DateAppr,
        TimeAppr,
        TAT,
        LaserLTR,
        Permit,
        LtrPrinter,
        JobName,
        JobNumber,
        JobDesc,
        ActQty,
        (ActQty-LtrPrinted) AS L,
        (ActQty-QtyInserted) AS M,
        ((ActQty-LtrPrinted)-(ActQty-QtyInserted)) AS N
    FROM 
        [test].[dbo].[MM]
    WHERE 
        DateDropped = 0
        AND (
        (ISNULL(@JobsOnHold, 0) = 1 AND DateAppr >= 0) 
        OR 
        (ISNULL(@JobsOnHold, 0) != 1 AND DateAppr != 0)
        )
    

    You can read more about conditional WHERE here.

提交回复
热议问题