Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stored procedure returning value

using this code :

ALTER PROCEDURE [dbo].[get](@i int)
AS
BEGIN
    declare @ADate datetime
    select @ADate = ADate 
    from table
    where i=@i
    and DateDiff(day ,getDate(), aDate  ) > 0
    and aDate is not null
    order by aDate asc
    return select @ADAte   
END

this returns 0 (or system 0 date time, which is not the desired result from the data base).

execute code

Declare @res datetime

exec @res = get 3

print @res

why?

like image 647
none Avatar asked Dec 03 '22 10:12

none


1 Answers

Stored Procedures in SQL Server can only RETURN integers. If you need to return anything other than a single integer, then you should use one of these methods (some explained by the previous answers):

  • Use a SELECT in your procedure

  • Use an OUTPUT Parameter

  • Use a User Defined Function instead

like image 195
RBarryYoung Avatar answered Dec 11 '22 10:12

RBarryYoung