日期:2014-05-17 浏览次数:20633 次
if exists( select 1 from test t where not exists(select 1 from test where billid=t.billid and qty<=0) ) print 'T' else print 'F'
------解决方案--------------------
--> 测试数据:[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 all
select 1,2,44 union all
select 1,3,55 union all
select 1,4,-3 union all
select 1,5,88
select
case
when exists(select 1 from test where [QTY]<0)
then 'F' else 'T' end as [state]
/*
state
------------
F
*/