Solved

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

Posted on 2016-09-23
2
97 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 69

Accepted Solution

by:
Scott Pletcher earned 500 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

839 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