I am trying to write a stored procedure in SQL but I am getting an error when creating it. The code: CREATE PROCEDURE CheckForCalls IF (SELECT max(StartDateTime) FROM dbo.Calls WHERE Recorded = 'true' AND CallDirection = 1) < DATEADD(minute, - 30, GETDATE())beginexec AnotherSPendgo
When I try to execute I get: Msg 156, Level 15, State 1, Procedure CheckForCalls, Line 4Incorrect syntax near the keyword 'IF'.
I'm not sure what I am doing wrong, the if statement works if I run it on it's own in a query. I can do: IF (SELECT max(StartDateTime) FROM dbo.Calls WHERE Recorded = 'true' AND CallDirection = 1) < DATEADD(minute, - 30, GETDATE())print 'NO'elseprint 'YES'
This works fine. Hopefully someone can tell me what I am doing wrong. Thanks!