Solved

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

Posted on 2016-09-23
2
250 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

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.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
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
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

734 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