Solved

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

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

772 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