Solved

Errors with SQL syntax

Posted on 2013-02-07
5
334 Views
Last Modified: 2013-02-07
IF (Select * from Lenovo_Events where Event_Key = @Event_Key) IS NULL THEN INSERT INTO Lenovo_Events VALUES (@Event_Date,@Line_Key, @Shift_Key, @Total_Qty, 0,0) ELSE UPDATE Lenovo_Events set Total_Qty = @Total_Qty where Event_Key = @Event_Key) END IF

Error:

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Incorrect syntax near the keyword 'THEN'.
Incorrect syntax near the keyword 'ELSE'.
Incorrect syntax near ')'.
0
Comment
Question by:JessyRobinson1234
[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
5 Comments
 
LVL 12

Expert Comment

by:Jared_S
ID: 38863979
IF (Select * from Lenovo_Events where Event_Key = @Event_Key) IS NULL
INSERT INTO Lenovo_Events VALUES (@Event_Date,@Line_Key, @Shift_Key, @Total_Qty, 0,0)
ELSE
UPDATE Lenovo_Events set Total_Qty = @Total_Qty where Event_Key = @Event_Key)
0
 
LVL 11

Accepted Solution

by:
Simone B earned 350 total points
ID: 38863982
Try this:

IF NOT EXISTS (Select * from Lenovo_Events where Event_Key = @Event_Key)  
INSERT INTO Lenovo_Events VALUES (@Event_Date,@Line_Key, @Shift_Key, @Total_Qty, 0,0) ELSE UPDATE Lenovo_Events set Total_Qty = @Total_Qty where Event_Key = @Event_Key
0
 
LVL 12

Expert Comment

by:Jared_S
ID: 38863983
You might also try:

IF NOT EXISTS (Select * from Lenovo_Events where Event_Key = @Event_Key)
INSERT INTO Lenovo_Events VALUES (@Event_Date,@Line_Key, @Shift_Key, @Total_Qty, 0,0)
ELSE
UPDATE Lenovo_Events set Total_Qty = @Total_Qty where Event_Key = @Event_Key)
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 38864093
remove the END IF

and retry

IF (Select * from Lenovo_Events where Event_Key = @Event_Key) IS NULL THEN INSERT INTO Lenovo_Events VALUES (@Event_Date,@Line_Key, @Shift_Key, @Total_Qty, 0,0) ELSE UPDATE Lenovo_Events set Total_Qty = @Total_Qty where Event_Key = @Event_Key) END IF

1 it should only be END
2 you only have an END if you also have a matching prior BEGIN

other points of concern
1. always specify the column list that you are presenting to the insert...
     insert into table (columnlist) values (1,2,3...)
2. shouldn't one of the columns in the values clause be @event_key?
3. not clear , but relationaly suspect why you can just update the total_qty without checking/updating the shift/line key values...


ps the IF not Exists (select ...) then ... is normally considered the standard syntax.
0
 

Author Closing Comment

by:JessyRobinson1234
ID: 38864249
This was the only one working for me. Thank you everyone.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

628 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