JessyRobinson1234
asked on
Errors with SQL syntax
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.PageRequestMa nagerServe rErrorExce ption: Incorrect syntax near the keyword 'THEN'.
Incorrect syntax near the keyword 'ELSE'.
Incorrect syntax near ')'.
Error:
Microsoft JScript runtime error: Sys.WebForms.PageRequestMa
Incorrect syntax near the keyword 'ELSE'.
Incorrect syntax near ')'.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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)
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)
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.
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.
ASKER
This was the only one working for me. Thank you everyone.
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)