当前位置: 代码迷 >> Sql Server >> 怎么判断表某列内容并返回值
  详细解决方案

怎么判断表某列内容并返回值

热度:89   发布时间:2016-04-27 11:29:37.0
如何判断表某列内容并返回值

如何判断表某列内容并返回值
MSSQL2000

表 TEST,
列
BILLID , ITEMNO,QTY
  1 , 1 , 2
  1 , 2 , 44
  1 , 3 , 55
  1 , 4 , 88

如何可以判断到该列QTY全部大于0时返回T,如果有其中一个数小于0则返回F



------解决方案--------------------
SQL code
if exists(select 1 from test twhere not exists(select 1 from test where billid=t.billid and qty<=0))  print 'T'else   print 'F'
------解决方案--------------------
SQL code
--> 测试数据:[TEST]if object_id('[TEST]') is not null drop table [TEST]create table [TEST]([BILLID] int,[ITEMNO] int,[QTY] int)insert [TEST]select 1,1,2 union allselect 1,2,44 union allselect 1,3,55 union allselect 1,4,-3 union allselect 1,5,88select      case         when exists(select 1 from test where [QTY]<0)             then 'F' else 'T' end as [state]/*state------------F*/
  相关解决方案