开发者

Conditional statement in sql server 2k5

开发者 https://www.devze.com 2022-12-29 18:51 出处:网络
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 th

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

精彩评论

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