I have a table that has one date field that is the week number and then 7 decimal fields that represents the hours worked.
I want to loop through this table and create a row in a temp table for each day of the week with the hours worked each day.
I could do a simple ...
SELECT UserID, WeekNum, Hours1, Hours2, Hours3, Hours4, Hours5, Hours6, Hours7
INTO #NCExtract
FROM Timesheet
But I need to have a result
UserID Date Hours
UserID Date Hours
UserID Date Hours
UserID Date Hours
UserID Date Hours
UserID Date Hours
UserID Date Hours
from one row. So I began the following way:
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
I am not sure how to provide the info in the loop to create the records.