Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- update t1
- set t1.CollectedData_ID = res.CollectedData_ID
- from Tasks t1
- join ImportSessions i1 on i1.ImportSession_ID = t1.ImportSession_ID
- join dbo.Periods p1 on i1.Session_Date between p1.Date_Begin and ISNULL(p1.Date_End, GETDATE()+1)
- join (
- select t.Task_ID, MAX(cd.CollectedData_ID) CollectedData_ID
- from CollectedData cd
- join Tasks t on t.Task_ID = cd.Task_ID
- join ImportSessions i on i.ImportSession_ID = t.ImportSession_ID
- join dbo.Periods p on i.Session_Date between p.Date_Begin and ISNULL(p.Date_End, GETDATE()+1)
- where p.Period_ID = 35
- and cd.Controller_ID = 12847
- and cd.CollectedData_ID<t.CollectedData_ID
- group by t.Task_ID
- ) res on t1.Task_ID = res.Task_ID
- join CollectedData res_cd on res.CollectedData_ID = res_cd.CollectedData_ID
- join CollectedData cd1 on t1.CollectedData_ID = cd1.CollectedData_ID
- where
- p1.Period_ID=35
- and cd1.Controller_ID = 39216
- and isnull(cd1.Check_Value,cd1.TypicalCase_ID) = ISNULL(res_cd.Check_Value, res_cd.TypicalCase_ID)
Add Comment
Please, Sign In to add comment