【发布时间】:2016-07-11 18:16:55
【问题描述】:
我有一张表,其中有一个日期字段是周数,然后是 7 个十进制字段表示工作时间。
我想遍历这个表,并在一个临时表中为一周中的每一天创建一行,其中包含每天的工作时间。
我可以做一个简单的...
SELECT UserID, WeekNum, Hours1, Hours2, Hours3, Hours4, Hours5, Hours6, Hours7
INTO #NCExtract
FROM Timesheet
但我需要有结果
UserID Date Hours
UserID Date Hours
UserID Date Hours
UserID Date Hours
UserID Date Hours
UserID Date Hours
UserID Date Hours
从一排开始。于是我开始了以下方式:
create table #NCExtract
(
UserID int,
WorkDate DateTime,
WorkHours decimal
)
Select *
From TimeSheetTable
While (Select Count(*) From TimeSheetTable) > 0
Begin
Create #NCExtract record with 1st date hours
Create #NCExtract record with 2nd date hours
Create #NCExtract record with 3rd date hours
Create #NCExtract record with 4th date hours
Create #NCExtract record with 5th date hours
Create #NCExtract record with 6th date hours
Create #NCExtract record with 7th date hours
End
我不确定如何在循环中提供信息来创建记录。
【问题讨论】:
标签: sql-server tsql temp