select EmpID,
Day1_A=(select OnDuty1 from 班次表 where 排班表.Day1_A=班次表.ID),
Day1_P=(select OffDuty2 from 班次表 where 排班表.Day1_P=班次表.ID),
Day1_A=(select OnDuty1 from 班次表 where 排班表.Day1_A=班次表.ID),
Day1_P=(select OffDuty2 from 班次表 where 排班表.Day1_P=班次表.ID),
...
Day31_A=(select OnDuty1 from 班次表 where 排班表.Day31_A=班次表.ID),
Day31_P=(select OffDuty2 from 班次表 where 排班表.Day31_P=班次表.ID)
from 排班表
Day1_A=(select OnDuty1 from 班次表 where 排班表.Day1_A=班次表.ID),
Day1_P=(select OffDuty2 from 班次表 where 排班表.Day1_P=班次表.ID),
Day1_A=(select OnDuty1 from 班次表 where 排班表.Day1_A=班次表.ID),
Day1_P=(select OffDuty2 from 班次表 where 排班表.Day1_P=班次表.ID),
...
Day31_A=(select OnDuty1 from 班次表 where 排班表.Day31_A=班次表.ID),
Day31_P=(select OffDuty2 from 班次表 where 排班表.Day31_P=班次表.ID)
from 排班表
解决方案 »
- 含有 IDENTITY 字段的表如何同表复制数据
- 字符串分割统计问题。
- 提示:OLE DB 提供程序 'MICROSOFT.JET.OLEDB.4.0' 报错。提供程序未给出有关错误的任何信息!
- 安装SQL2000 SP4补丁的时候出错
- 高手啊!帮我看看,急啊!!!
- 简单的存储过程问题
- 如何利用alter Table命令,将表中的某列设置为identity属性?
- 能否将sql server 中一张表中的某些字端 导入 sql server中另一数据库中的另一张表的某些字段中去?
- 在机器上经常出现Sql server连不上本机的数据库,怎么回事?
- 关于TStoredProcedure与Sql-server连接问题,很怪的....
- 一个简单的问题
- SQL 问题
select EmpID,
Day1_A=(select top 1 OnDuty1 from 班次表 where ID=a.Day1_A),
Day1_P=(select top 1 OffDuty2 from 班次表 where ID=a.Day1_P),
--...
from 排班表 a
case when a.Day1_P=b.ID then a.Day1_P=b.OffDuty2 else
..................................
不知道对不对
排班表的 Day1_A Day1_P 对应班次表的 OnDuty1 OffDuty2
,Day1_A=b1.OnDuty1 , Day1_P=b1.OffDuty2
,Day2_A=b2.OnDuty1 , Day2_P=b2.OffDuty2
....
,Day31_A=b31.OnDuty1 , Day31_P=b31.OffDuty2
from 排班表 a
left join 班次表 b1 on a.Day1_A=b1.ID
left join 班次表 b2 on a.Day2_A=b2.ID
...
left join 班次表 b31 on a.Day31_A=b31.ID
E 事假
F 病假请假是半天半天的请,请问上列查询如何再加入假期表的判断?
Day1_A=isnull( (select top 1 OnDuty1 from 班次表 where ID=a.Day1_A),
(select top 1 Name from 假期表 where Holiday_CODE =a.Day1_A) ),
...
Day1_A=(select top 1 OnDuty1 from 班次表 where ID=a.Day1_A),现在改成这样Day1_A=isnull((select top 1 OnDuty1 from 班次表 where ID=a.Day1_A),
(select top 1 Name from 假期表 where Holiday_CODE =a.Day1_A)
),
from 班次表 a,假期表 b
where ID=a.Day1_A or b.Holiday_CODE =a.Day1_A)
),