I am trying to create a stored proc and have a where clause where to different operations can take place depending on the value of a parameter passed in:
WHERE
(cdr.CircuitReference = @CircuitReference)
AND
CASE WHEN (@JDEDocumentReference <> 'Unbilled Calls')
THEN
sct.JDEDocumentReference = @JDEDocumentReference
ELSE
((sct.JDEDocumentReference IS NULL) AND (sc.StartDate IS NOT null AND ((sc.CloseDate IS null) OR (datediff(day,sc.CloseDate,getdate()) < 0)) AND stp.SipTrunksProduct = sct.ProductCode))
END
I've just posted my where clause above but when i try to execute the script i get the following error:
Incorrect syntax near '='.
Is this the correct way to do a conditional statement in a where clause of an sql query?
Thanks