I have an SP, and this part of it:
if exists (
With a as ( select timestamp, row_number() over (order by timestamp desc) as rown,
level from dbo.fm_fuel order by Timestamp fetch first 2 rows only)
Select t1.timestamp, t1.level, t2.timestamp, t2.level
from a t1 inner join a t2 on t1.rown=t2.rown+1 where t1.mjid=3199 and (t2.level - t1.level) > 9;
INSERT INTO DBO.FM_REFUEL (TIMESTAMP, MJID, CHID, LEVEL, ODOMETER)
(CDTWHEN, IMJID, CCHID, iLEVEL, iODOMETER);
gives me this error:
ERROR: A character, token, or clause is invalid or missing.
SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=as;if
With a;JOIN, DRIVER=3.57.82
Error Code: -104
The statament works by itself, but how do I make it work inside a stored procedure?
Any help is appreciated, thank you