I have a table with 4 columns readdate, tagname, value and amendedvalue in MSSQL 2008. The first 3 are inserted by an sql job running at 8am in the morning and contain data ranging from 7am the previous day to 7am the current day in hourly averages. The amended value can be changed via a web application by the user.I want to be able to look at the previous days data and if there is a value in the amendedvalue column then update the same range the next day. It will always be for the same range ie if the amended value is changed for tagname1 for the previous 24 hours then the next day will need to show the same value in the amendedvalue column for that 24 hour period.here is the code I have so fardeclare @amendedvalue intSELECT @AmendedValue = amendedValueFROM gasdataWhere tagname ='35FI8316' and readDate BETWEEN DateAdd(Hour, 7, DateAdd(Day, DateDiff(Day, 0, GETDATE()), -2)) and dateadd(hour, 6, DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0))IF @AmendedValue is not nullBEGIN update gasdata set amendedValue = ???? where tagname ='35FI8316' and readDate BETWEEN DateAdd(Hour, 7, DateAdd(Day, DateDiff(Day, 0, GETDATE()), -1)) and dateadd(hour, 6, DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0))END
I basically need to know what goes in the ???? after amendedvalue = so it picks up the values from the previous date range and inserts them into the latest rangeHope that makes sense