我目前正在制作一个存储过程,为用户提供一个可以向下钻取的过滤系统。现在我难以尝试在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语句,但没有占优势,也是一个案例陈述。是否可以使用条件OR或AND语句?
答案 0 :(得分: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)))