日期:2014-05-18 浏览次数:21076 次
select (case when exists (select 1 from tb where col <= 0) then 'F' else 'T' end)
------解决方案--------------------
declare @t table (billid int,viplbsl2 decimal(18,5)) insert into @t select 1,0 union all select 1,2 union all select 1,3 union all select 1,4 union all select 1,0 select *, newcol=case when sign(billid)<>-1 and sign(viplbsl2)<>-1 then 'T' else 'F' END from @t select *, newcol=case when billid>0 and viplbsl2>0 then 'T' else 'F' END from @t /* billid viplbsl2 newcol ----------- --------------------------------------- ------ 1 0.00000 T 1 2.00000 T 1 3.00000 T 1 4.00000 T 1 0.00000 T */
------解决方案--------------------
--要求: --这一列如果有其中一个值是大于0的则为T declare @t table (billid int,viplbsl2 decimal(18,5)) insert into @t select 1,0 union all select 1,2 union all select 1,3 union all select 1,4 union all select 1,0 declare @i int select @i= sum(case when viplbsl2>0 then 1 else 0 end ) from @t print @i select (case when @i<= 0 then 'F' else 'T' end) --只要有一个有一个大于0的就返回T,否则就是F ---- T (1 行受影响)