怎样合并列?

yuga 2003-08-25 02:04:37
date 值班队长 值班人 看门人
2003-8-25 甲 乙 丙

怎么选出今天值班人员
用于判断这个人今天是否值班
...全文
32 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
txlicenhe 2003-08-25
  • 打赏
  • 举报
回复
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
yuga 2003-08-25
  • 打赏
  • 举报
回复
to txlicenhe(不做技术高手)

那我怎么将他合并到表里面?这一列本来是没有的
人员号 姓名 今天值班
3 李 否
CrazyFor 2003-08-25
  • 打赏
  • 举报
回复
select * from 表 convert(char(10),date字段,120)=convert(char(10),getdate(),120)
txlicenhe 2003-08-25
  • 打赏
  • 举报
回复
declare @xm varchar
set @xm = '张三'

if Exists(Select * from 表 where @xm in (值班队长,值班人,看门人) and datediff(day,date,getdate()) = 0 )
print @xm + '今天要值班'
else
print @xm + '今天不用值班'
king0401 2003-08-25
  • 打赏
  • 举报
回复
Select 值班队长 from yourTable
union all
Select 值班人 from yourTable
union all
Select 看门人 from yourTable
where datediff(day,[date],getdate())=0
pengdali 2003-08-25
  • 打赏
  • 举报
回复
select * from 表 datediff(day,[date],getdate())=0
txlicenhe 2003-08-25
  • 打赏
  • 举报
回复
Select date,值班队长 from yourTable
union all
Select date,值班人 from yourTable
union all
Select date,看门人 from yourTable




22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧