I have a SQL Server table that has production running times for different pieces of equipment organized by date and shift.
For example:
Date, Shift, Running Hours
7/11/14, 1, 4.2
My problem is that on weekdays, there are 3 eight hour shifts but on weekends there are 2 twelve hour shifts. All the data is being stored based on 3 shifts regardless of day of the week.
In plain English, on weekends I need to take the 2nd shift running times, divide it by two and add it to the 1st and 3rd shift times. Also, the 1st and 3rd shifts on the weekends need to be relabeled as 4th and 5th shifts because they are not of equal duration as the weekday shifts.
I cannot touch the data in the original table, I essentially need to have a live copy of the data in another table (or view?) and manipulate it there. I started by creating a view off of the mother table and then tried to do an update statement. I started with just updating the shift number but I just can't seem to get it off the ground.
Is using a view even the correct method? Will updating the view change the values in the original table? Or should I have another table that is populated by a stored procedure which has all the manipulations in it?
Thank you for any help you may be able to provide. And I apologize for any formatting problems. This is my first post.
SELECT TOP (100) PERCENT
ShiftNumber, TowerString,
convert(varchar,a.ShiftDateTime,101) AS Day, Running,
FROM
DBName.dbo.ShiftDetails
UPDATE
v_ViewName
SET
ShiftNumber = 4
WHERE
DATENAME(dw, Day) = 'Saturday' AND ShiftNumber = 1