select 中使用 case when 和 replace

来源:互联网 发布:社会经济数据库 编辑:程序博客网 时间:2024/06/05 03:16

在SELECT中,用CASE  
例如:  
  select   a.Cname   as   Tcomname,b.Cname   as   TGoodname,D.nQuanty,c.cNote,   (case   when   c.iEvaluate='-1'  then   '差评'  when   c.iEvaluate='1'   then   '好评'   when   c.ievaluate='0'   then   '一般'   end)   as   ievaluate    
  from   Tcompany   a,Tgoods   b,Appraise   c,orders   D  
  where   b.ID=D.nProductID   and   D.Id=c.order_id   and   a.Id=b.NsaID  
  and   b.NsaID=@TcomIDTop

 

select 和 replace
select AdID,replace(replace(cast(AdClassID as varchar(50)) ,'0','头条新闻头部'),'1','头条新闻尾部') as AdClassID,Title,LinkUrl,UpdateTime from Advertisement order by AdID