Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to resolve the error "Incorrect syntax near '='." when executing a stored proc in SQL Server 2008?

Posted on 2016-09-23
2
Medium Priority
?
623 Views
Last Modified: 2016-09-23
When I execute the following stored procedure in SQL Server 2008, I get the error

Msg 102, Level 15, State 1, Procedure proc_CSL_AutoDetStop, Line 7
Incorrect syntax near '='.

Do you know how I can resolve this error?


USE [CSL]
GO
/****** Object:  StoredProcedure [dbo].[proc_CSL_AutoDetStop]    
SET ANSI_NULLS OFF
GO
GO
ALTER PROCEDURE [dbo].[proc_CSL_AutoDetStop]
AS
SELECT dbo.tbl_CSL_Bank.entity, dbo.tbl_CSL_StopVoidPay.bank, dbo.tbl_CSL_StopVoidPay.userid, dbo.tbl_CSL_StopVoidPay.dtCreated,
dbo.tbl_CSL_StopVoidPay.chkNum, dbo.tbl_CSL_StopVoidPay.branch, dbo.tbl_CSL_StopVoidPay.chkDt, dbo.tbl_CSL_StopVoidPay.accountNum, dbo.tbl_CSL_StopVoidPay.amount,
dbo.tbl_CSL_StopVoidPay.typeSV
FROM dbo.tbl_CSL_Bank INNER JOIN dbo.tbl_CSL_StopVoidPay ON dbo.tbl_CSL_Bank.bankID = dbo.tbl_CSL_StopVoidPay.bank
WHERE (((dbo.tbl_CSL_StopVoidPay.typeSVB)='S') AND ((Exists (select msidOld from dbo.tbl_CSL_Users where dbo.tbl_CSL_StopVoidPay.userid = dbo.tbl_CSL_Users.msidOld))=False))
ORDER BY dbo.tbl_CSL_StopVoidPay.chkNum;
0
Comment
Question by:zimmer9
2 Comments
 
LVL 70

Accepted Solution

by:
Scott Pletcher earned 2000 total points
ID: 41812820
You don't use "=False" to fail EXISTS, you use "NOT EXISTS" instead:

ALTER PROCEDURE [dbo].[proc_CSL_AutoDetStop]
AS
SELECT dbo.tbl_CSL_Bank.entity, dbo.tbl_CSL_StopVoidPay.bank, dbo.tbl_CSL_StopVoidPay.userid, dbo.tbl_CSL_StopVoidPay.dtCreated,
dbo.tbl_CSL_StopVoidPay.chkNum, dbo.tbl_CSL_StopVoidPay.branch, dbo.tbl_CSL_StopVoidPay.chkDt, dbo.tbl_CSL_StopVoidPay.accountNum, dbo.tbl_CSL_StopVoidPay.amount,
dbo.tbl_CSL_StopVoidPay.typeSV
FROM dbo.tbl_CSL_Bank INNER JOIN dbo.tbl_CSL_StopVoidPay ON dbo.tbl_CSL_Bank.bankID = dbo.tbl_CSL_StopVoidPay.bank
WHERE (((dbo.tbl_CSL_StopVoidPay.typeSVB)='S') AND
       (Not Exists (select msidOld from dbo.tbl_CSL_Users
                            where dbo.tbl_CSL_StopVoidPay.userid = dbo.tbl_CSL_Users.msidOld)))
ORDER BY dbo.tbl_CSL_StopVoidPay.chkNum;
0
 
LVL 34

Expert Comment

by:Brian Crowe
ID: 41812870
Side Note...please look into aliasing your tables
1

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question