我正在尽最大努力将一周中的日子变成 X,这样我就可以在每周的时间表上标记它们 - 将它们组合在一条线上是我的症结所在。
预期输出:
AgrmntID Description RepairID Su M Tu W Th F Sa
2 Landscaping 2 X
3 Landscaping 2 X X X X X X
电流输出:
AgrmntID Description RepairID
2 Landscaping 2
当前代码:
Select Agreements.AgrmntID, LaborCodeTypes.Description,
AgreementSchedules.RepairID
From Agreements Inner Join
AgreementSchedules On Agreements.AgrmntID = AgreementSchedules.AgrmntID
Inner Join
LaborCodeTypes On LaborCodeTypes.RepairID = AgreementSchedules.RepairID
Inner Join
(Select AgreementSchedules.AgrmntID, AgreementSchedules.RepairID, Case
When DatePart(dw, AgreementSchedules.SchedDate) = 1 Then 'X'
End As Sunday
From AgreementSchedules
Where AgreementSchedules.RepairID = 2
Union
Select AgreementSchedules.AgrmntID, AgreementSchedules.RepairID, Case
When DatePart(dw, AgreementSchedules.SchedDate) = 2 Then 'X'
End As Monday
From AgreementSchedules
Where AgreementSchedules.RepairID = 2
Union
Select AgreementSchedules.AgrmntID, AgreementSchedules.RepairID, Case
When DatePart(dw, AgreementSchedules.SchedDate) = 3 Then 'X'
End As Tuesday
From AgreementSchedules
Where AgreementSchedules.RepairID = 2) Sched On Sched.AgrmntID =
Agreements.AgrmntID
Group By Agreements.AgrmntID, LaborCodeTypes.Description,
AgreementSchedules.RepairID
Having AgreementSchedules.RepairID = 2
我有很多我失败的例子,如果这可以帮助你解决这个问题。任何提示将不胜感激 - 在此先感谢您!