user3014776
user3014776

Reputation: 13

SQL If NOT EXISTS Syntax error

IF NOT EXISTS (SELECT prereqListID
               FROM   dbo.tblPreRequisiteList
               WHERE  NOT prereqListID IN (SELECT FK_prereqID
                                           FROM   dbo.tblPreReqStudentAnswers
                                           WHERE  FK_applicantID = @appID))

I have a syntax error in this statement that I can't seem to identify.

Any thoughts?

Thanks for your time.

Upvotes: 0

Views: 3068

Answers (1)

Martin Smith
Martin Smith

Reputation: 453328

Executing the code in the question will give the error

Incorrect syntax near ')'.

You need to follow it with another statement/block

IF NOT EXISTS (SELECT prereqListID
               FROM   dbo.tblPreRequisiteList
               WHERE  NOT prereqListID IN (SELECT FK_prereqID
                                           FROM   dbo.tblPreReqStudentAnswers
                                           WHERE  FK_applicantID = @appID))
BEGIN
SomethingHere:
END        

Upvotes: 2

Related Questions