开发者

Conditional statement in sql server 2k5

How would I filter this query to NOT show any items where "discontinued =1" and quantity=0"? I don't want to exclude all items with a value of discontinued =1. This only applies if the item has the value of discontinued=1 and the quantity =0.

  select sku,producttitle,location,pt开发者_如何学Python_type as type, vendor_name, 
  active,pricestatus,  disc as discontinued,season,yourprice as  
  customerprice,costprice,quantity,stockvalue 

  from getskus


WHERE NOT (discontinued = 1 AND quantity = 0)

This represents exactly what you want to express. You exclude (keyword NOT) rows satisfying both (keyword AND) your desired conditions.


select sku
       ,producttitle
       ,location
       ,pt_type as type
       ,vendor_name
       ,active
       ,pricestatus
       ,disc as discontinued
       ,season
       ,yourprice as customerprice
       ,costprice
       ,quantity
       ,stockvalue  
from getskus 
WHERE NOT (disc = 1 and quantity= 0)


SELECT sku,
      producttitle,
      location,
      pt_type AS TYPE,
      vendor_name,
      ACTIVE,
      pricestatus,
      disc AS discontinued,
      season,
      yourprice AS customerprice,
      costprice,
      quantity,
      stockvalue
FROM  getskus
WHERE NOT (disc = 1 AND quantity = 0)

you can also change direction like this

SELECT sku,
       producttitle,
       location,
       pt_type AS TYPE,
       vendor_name,
       ACTIVE,
       pricestatus,
       disc AS discontinued,
       season,
       yourprice AS customerprice,
       costprice,
       quantity,
       stockvalue
FROM   getskus
WHERE  disc <> 1
       OR  quantity <> 0

But I would prefer the first one

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜