34,575
社区成员
发帖
与我相关
我的任务
分享
select * from @table a where
cn = 123 and (an = all(select an from @table b where a.cn = b.cn) or an <> '')
declare @table table(id int,an char(1),cn int)
insert @table
select 1,'a',121
insert @table
select 2,'',123
insert @table
select 3,'s',123
select * from @table a where (cn = 123 and an = all(select an from @table b where a.cn = b.cn))
or (cn = 123 and an <> '')
/*
id an cn
----------- ---- -----------
3 s 123
*/
delete from @table where id = 3
select * from @table a where (cn = 123 and an = all(select an from @table b where a.cn = b.cn))
or (cn = 123 and an <> '')
/*
id an cn
----------- ---- -----------
2 123
(1 row(s) affected)
*/
if(exists(select 1 from tb where an != '' and cn='123') )
exec('select * from tb where an !='''' and cn =''123''')
else
exec('select * from tb where an ='''' and cn =''123''')
drop table tb
create table tb (id int,AN varchar(8000),CN varchar(8000))
insert tb select 1,'a','121'
insert tb select 2,'','123'
insert tb select 3,'s','123'
create table tb (id int,AN varchar(8000),CN varchar(8000))
insert tb select 1,'a','121'
insert tb select 2,'','123'
if(exists(select 1 from tb where an != '' and cn='123') )
print '有'
else
print '无'
if(exists(select 1 from tb where an != '' and cn='123') )
exec('select * from tb where an !='''' and cn =''123''')
else