值得品味的SQL

1 拼配名称和编号的结果集

SELECT t1.Shop_ID,
       t1.Goods_TypeID,
       t1.Goods_ID,
       t1.Goods_Name,
       t1.Goods_ShortName,
       t1.Goods_Lenght,
       t1.Goods_Height,
       t1.Weight_Unit,
       t1.Goods_Unit,
       t1.NetWeight,
       t1.RoughWeight,
       t1.Cost_Price,
       t1.Standard_Price,
       case
         when t2.Stock_Amount IS NULL then
          '0'
         ELSE
          t2.Stock_Amount
       END Stock_Amount
  FROM T_Base_GoodsInfo t1
  left join T_IM_StockInfo t2 ON t1.Goods_ID = t2.Goods_ID
 where 1 = 1
   and t1.Goods_State = '0'
   and Stock_Amount > 0
   and (t1.Goods_ID like '%0702010016%' or
       t1.Goods_Name like '%0702010016%')

 

 

posted @ 2013-05-11 10:25  杨斌_济南  阅读(212)  评论(0编辑  收藏  举报