我想在taskid上使用startdate enddate.based 在数据库中,datatable数据包含类似 表:
TaskId Mondate tuedate weddate...sundate monhours tuehours wedhours thuhours.... sunhours
Tsk100 3/6/13 4/6/13 5/6/13.. 9/6/13 Null 2 2 1 2
所以这次我想要像startdate = 4/6/13和enddate = 9/6/13。 所以请帮帮我?
答案 0 :(得分:0)
您可以使用CASE
。将....
替换为其余的日间小时列及其相关日期。
SELECT StartDate = CASE
WHEN monhours IS NOT NULL THEN mondate
ELSE
CASE
WHEN tuehours IS NOT NULL THEN tuedate
....
ELSE
CASE
WHEN sunhours IS NOT NULL THEN sundate
END
END
END,
EndDate = CASE
WHEN sunhours IS NOT NULL THEN sundate
....
ELSE
CASE
WHEN monhours IS NOT NULL THEN mondate
END
END
FROM dbo.tablename