0
I am trying to create a stored precedent that checks whether the table is empty or not, if it is empty returns -1, if it is not empty return the most recent element of the table.
I’m trying this way :
CREATE PROCEDURE spAVL_Ignition
AS
BEGIN
SELECT Value
FROM AVL_Ignition
WHERE TimeStamp = (SELECT MAX(TimeStamp) FROM AVL_Ignition)
IF @@ROWCOUNT = 0
RETURN -1
END
It works normally when the table is filled, but when the table is empty it does not signal me, in case it does not return the '-1'. What’s wrong ?
How is the use of Procedure?
– Sorack
@Sorack am running Procedure in a query.
– Levi
So it all depends on the way you’re calling it from the past. To get the -1 you have to assign it to a variable. Otherwise you need to change the Return to
SELECT -1
– Sorack
@Sorack I used select instead of Return and it worked. Thank you.
– Levi