22,209
社区成员
发帖
与我相关
我的任务
分享
select id ,case when name='' then 'have age is: '+age else 'have name is: '+name end as message
from 你的表
declare @tb table (id int,name varchar(10),age varchar(10))
insert into @tb select 1,'xu',''
insert into @tb select 2,'10','5'
insert into @tb select 3,'xzx',''
insert into @tb select 4,'','6'
select id ,case when name='' then 'have age' else 'have name' end as [message]
from @tb
declare @tb table (id int,name varchar(10),age varchar(10))
insert into @tb select 1,'xu',''
insert into @tb select 2,'10','5'
insert into @tb select 3,'xzx',''
insert into @tb select 4,'','6'
select id ,max(case when name='' then 'have age' else 'have name' end) as [message]
from @tb group by id
declare @tb table (id int,name varchar(10),age varchar(10))
insert into @tb select 1,'xu',''
insert into @tb select 2,'','5'
insert into @tb select 3,'xzx',''
insert into @tb select 4,'','6'
select id ,max(case when name='' then age else name end)
from @tb group by id
select id,isnull(name,cast(age as varchar(10))) as message from 表