How do I write an IF statement with multiple arguments in T-SQL?
Current source error:
DECLARE @StartDate AS DATETIME
DECLARE @EndDate AS DATETIME
SET @StartDate = NULL
SET @EndDate = NULL
IF (@StartDate IS NOT NULL AND @EndDate IS NOT NULL)
BEGIN
-- do some work
END
It throws the following error:
Incorrect syntax near the keyword
‘AND’. Incorrect syntax near the
keyword ‘AND’. Incorrect syntax near
‘)’.
You are doing it right. The empty code block is what is causing your issue. It’s not the condition structure 🙂