Problem with stored Procedure

Asked

Viewed 30 times

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 am running Procedure in a query.

  • 2

    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

  • 1

    @Sorack I used select instead of Return and it worked. Thank you.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.