Solved

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

Posted on 2016-09-23
2
46 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:
ScottPletcher 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
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.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now