I have a query to first check if something exists. If yes, insert something into a table variable. Otherwise, insert something else into the same table variable.
IF NOT EXISTS (SELECT 1 FROM @Main WHERE CustomerId = @CustomerId)
(
BEGIN
INSERT INTO @Result
SELECT ....
FROM ...
WHERE...
END
)
ELSE
INSERT INTO @Result
SELECT ....
FROM ...
WHERE...
For some reason I keep getting the errors below complaining inside the NOT EXISTS
condition... The ELSE part is completely fine.
Incorrect syntax near the keyword 'BEGIN'
Incorrect syntax near ')'
Incorrect syntax near '@Result'
Where did I do wrong?