I was wondering if anybody could help me. My boss wants me to get rid of my If Else statements and use a CASE WHEN statement to use a single Insert Statement to insert data into a table.
This is the first time I've attempted to use a CASE expression within a INSERT statement.
Here is my code:
I keep getting a "Syntax error near the word 'CASE'" error.
Does anybody see he error of my ways??
Thanks in advance
This is the first time I've attempted to use a CASE expression within a INSERT statement.
Here is my code:
Code:
INSERT INTO tblDBChanges (PatientVisitID, Reason, logText, created, createdBy)
CASE @tempLock
When 1 Then Values (@tempPVID, 'Lock Release (Letters)',@letterName + ' was locked on: Faxed', getdate(), @user)
When 4 Then Values (@tempPVID, 'Lock Release (Letters)',@letterName + ' was locked on: Printed or Printed to Queue', getdate(), @user)
When 8 Then Values (@tempPVID, 'Lock Release (Letters)',@letterName + ' was locked on: E-mailed', getdate(), @user)
When 10 Then Values (@tempPVID, 'Lock Release (Letters)',@letterName + ' was locked on: Whiteboard viewed', getdate(), @user)
End
I keep getting a "Syntax error near the word 'CASE'" error.
Does anybody see he error of my ways??
Thanks in advance