0

我目前正在制作一个存储过程,它为用户提供一个过滤系统以进行深入研究。现在我很难在 where 语句中加入条件子句。如下图所示:

 WHERE upper(stk.warehouse) LIKE '%' + upper(@warehouse) + '%' AND
       upper(stk.product) LIKE '%' + upper(@product) + '%' AND
       upper(stk.description) LIKE '%' + upper(@description) + '%' AND
       upper(stk.long_description) LIKE '%' + upper(@longdescription) + '%' AND
       cast(safety_stock_level as decimal(20)) LIKE '%' +
       upper(@barcode) + '%' AND        
       (stk.physical_qty + stk.on_order_qty -stk.allocated_qty - stk.back_order_qty -
       stk.uninspected_qty)>@available AND

    *if @or =0 BEGIN
    stk.on_order_qty > @onorder AND stk.physical_qty > @phys 
    else
    stk.on_order_qty > @onorder OR stk.physical_qty > @phys* 

现在我尝试了一个不占优势的 if 语句和一个 case 语句。是否有条件 OR 或 AND 语句?

4

1 回答 1

3

你会这样做:

((@or = 0 AND stk.on_order_qty > @onorder AND stk.physical_qty > @phys) OR
 (@or = 1 AND (stk.on_order_qty > @onorder OR stk.physical_qty > @phys)))  
于 2012-09-11T08:27:16.990 回答