I need to know what is the error in the following stored procedure, as begging with mySql I can\'t understand what is the error
if not EXISTS( select filesr
You have not used THEN keyword and END IF.
Try this:
SET @ExistedRefID = NULL;
SELECT ReferenceID INTO @ExistedRefID
FROM filesrefrences
WHERE RefrenceKey= pRefrenceKey;
IF (@ExistedRefID IS NULL) THEN
INSERT INTO filesrefrences(RefrenceKey, RefrenceCount)
VALUES(pRefrenceKey,1);
SELECT LAST_INSERT_ID();
ELSE
UPDATE filesrefrences
SET RefrenceCount= RefrenceCount+1
WHERE ReferenceID= @ExistedRefID;
SELECT @ExistedRefID;
END IF;