Skip to content

Instantly share code, notes, and snippets.

@stim371
Last active December 11, 2015 16:39
Show Gist options
  • Save stim371/4629551 to your computer and use it in GitHub Desktop.
Save stim371/4629551 to your computer and use it in GitHub Desktop.
two different pseudo-code examples to try to better explain what I was trying to achieve.
UPDATE c SET
CreateDate = CASE WHEN UPDATE ([CreateDateUTC]) THEN dbo.ConvertUTCTimeToPacific(i.CreateDateUTC)
ELSE CreateDate
END,
CreateDateUTC = CASE WHEN UPDATE ([CreateDate]) THEN dbo.ConvertPacificTimeToUTC(i.CreateDate)
ELSE CreateDateUTC
END
FROM dbo.Calls AS c
JOIN INSERTED AS i
ON i.CallId = c.CallId;
UPDATE c SET
IF UPDATE ([CreateDateUTC]) -- I'm not sure if this works, but do you need the case statement? (see note 1 below)
CreateDate = dbo.ConvertUTCTimeToPacific(i.CreateDateUTC)
IF UPDATE ([CreateDate])
CreateDateUTC = dbo.ConvertPacificTimeToUTC(i.CreateDate)
FROM dbo.Calls AS c
JOIN INSERTED AS i
ON i.CallId = c.CallId;
/* Note 1
Can't you conditionally set the value instead of always assigning it and switching whether it overwrites itself or gets converted?
*/
/* Note 2
This does not work
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment