Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can we return a null from stored procedure

Can we return null value from stored procedure. i dont want to use collase or isnull. I want to capture NULL at the frontend. Is it possible ?

Edit:

I am using Sql Server 2005

eg. where i want to use

CREATE PROCEDURE [Authentication].[spOnlineTest_CheckLogin]

  @UserName  NVARCHAR(50)
AS
 BEGIN TRY
  BEGIN TRAN
                    COMMIT TRAN
     RETURN NULL
        END TRY

Error The 'spOnlineTest_CheckLogin' procedure attempted to return a status of NULL, which is not allowed. A status of 0 will be returned instead. Msg 0, Level 11, State 0, Line 0 A severe error occurred on the current command. The results, if any, should be discarded.

like image 494
Shantanu Gupta Avatar asked Feb 25 '10 16:02

Shantanu Gupta


People also ask

Can stored procedure return null?

If you try to return NULL from a stored procedure using the RETURN keyword, you will get a warning, and 0 is returned instead. If a procedure hits an error that requires it to terminate immediately, it will return NULL because it never gets to either the RETURN keyword or the end of the batch!

Can we return from stored procedure?

Return Value in Stored Procedure. Return values can be used within stored procedures to provide the stored procedure execution status to the calling program. You can create your own parameters that can be passed back to the calling program. By default, the successful execution of a stored procedure will return 0.

How do I return a NULL function in SQL?

Any data type in SQL can be set to null unless a not null restriction is put on it. Therefore you should be able to use whatever return type best suits your needs... In your calling code, you'd have to check to see if the returned value is equal to DBNull. Value and have your code act accordingly.

Will count (*) ever return null?

No, it will only return a zero (or non-zero) result.


1 Answers

No, the return type of a stored procedure is INT and it cannot be null.

like image 171
mmx Avatar answered Nov 01 '22 18:11

mmx