Select 值班队长 from yourTable union all Select 值班人 from yourTable union all Select 看门人 from yourTable where datediff(day,[date],getdate())=0
declare @xm varchar set @xm = '张三'if Exists(Select * from 表 where @xm in (值班队长,值班人,看门人) and datediff(day,date,getdate()) = 0 ) print @xm + '今天要值班' else print @xm + '今天不用值班'
select * from 表 convert(char(10),date字段,120)=convert(char(10),getdate(),120)
to txlicenhe(不做技术高手) 那我怎么将他合并到表里面?这一列本来是没有的 人员号 姓名 今天值班 3 李 否
1: 你要有一个用户表吧,假设为 userTable (id int,name varchar(10)) 2: Select id,a.name, (case when name in (值班队长,值班人,看门人) then '是' else '否' end) as 今天值班 from userTable a left join 值班表 b on a.name = b.name where datediff(day,b.date,getdate()) = 0
union all
Select 值班人 from yourTable
union all
Select 看门人 from yourTable
where datediff(day,[date],getdate())=0
set @xm = '张三'if Exists(Select * from 表 where @xm in (值班队长,值班人,看门人) and datediff(day,date,getdate()) = 0 )
print @xm + '今天要值班'
else
print @xm + '今天不用值班'
人员号 姓名 今天值班
3 李 否
2: Select id,a.name,
(case when name in (值班队长,值班人,看门人) then '是' else '否' end) as 今天值班
from userTable a
left join 值班表 b on a.name = b.name
where datediff(day,b.date,getdate()) = 0