首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

判断某列值是否大于0,该怎么处理

2012-03-21 
判断某列值是否大于0判断某列任何一个数大于0返回真T,否则返回假FSQL2000表 otherin列int,decimal(18,5)bi

判断某列值是否大于0
判断某列任何一个数大于0返回真T,否则返回假F
SQL2000

表 otherin
列  
  int ,decimal(18,5)
billid ,viplbsl2  
 1 0
 1 2
 1 3
 1 4
 1 0

以上的结果应为真

 

[解决办法]

SQL code
select (case when exists (select 1 from tb where col <= 0) then 'F' else 'T' end)
[解决办法]
SQL code
declare @t table (billid int,viplbsl2 decimal(18,5))insert into @tselect 1,0 union allselect 1,2 union allselect 1,3 union allselect 1,4 union allselect 1,0select *,newcol=case when sign(billid)<>-1 and sign(viplbsl2)<>-1then 'T' else 'F' END from @tselect *,newcol=case when billid>0 and viplbsl2>0then 'T' else 'F' END from @t/*billid      viplbsl2                                newcol----------- --------------------------------------- ------1           0.00000                                 T1           2.00000                                 T1           3.00000                                 T1           4.00000                                 T1           0.00000                                 T*/
[解决办法]
SQL code
--要求:--这一列如果有其中一个值是大于0的则为Tdeclare @t table (billid int,viplbsl2 decimal(18,5))insert into @tselect 1,0 union allselect 1,2 union allselect 1,3 union allselect 1,4 union allselect 1,0declare @i intselect @i= sum(case when viplbsl2>0 then 1 else 0 end ) from @tprint @i    select (case when @i<= 0  then 'F' else 'T' end)    --只要有一个有一个大于0的就返回T,否则就是F  ----T(1 行受影响) 

热点排行