December 21, 2017 at 4:04 pm
This code works, but I don;t understand it. The part I need some clarification is on the Return @Severity. Why would that not be Return @StartDate? As it is written it return the results of dbo.startdate().
ALTER PROCEDURE GetStartDate(
@StartDate Datetime OUTPUT
)
AS
DECLARE
@Severity int
SET @Severity = 0
IF @StartDate IS NULL
SET @StartDate = dbo.startdate(0)
RETURN @Severity
DECALRE @StartDate DateTime
EXEC GetStartDate @StartDate OUTPUT
SELECT @StartDate
Thanks
Everett
December 21, 2017 at 4:50 pm
Post the DDL for dbo.startdate
December 21, 2017 at 5:09 pm
macbaze72 - Thursday, December 21, 2017 4:04 PMThis code works, but I don;t understand it. The part I need some clarification is on the Return @Severity. Why would that not be Return @StartDate? As it is written it return the results of dbo.startdate().ALTER PROCEDURE GetStartDate(
@StartDate Datetime OUTPUT
)
AS
DECLARE
@Severity intSET @Severity = 0
IF @StartDate IS NULL
SET @StartDate = dbo.startdate(0)RETURN @Severity
DECALRE @StartDate DateTime
EXEC GetStartDate @StartDate OUTPUT
SELECT @StartDateThanks
Everett
The value generated by the procedure dbo.startdate(0) is returned in the OUTPUT parameter @StartDate. The value in @Severity would be made available if GetStartDate is execute this way:
declare @StartDate DateTime, @result int;
EXEC @result = EXEC GetStartDate @StartDate OUTPUT;
SELECT @result, @StartDate;
Does that help?
December 21, 2017 at 5:15 pm
macbaze72 - Thursday, December 21, 2017 4:04 PMThis code works, but I don;t understand it. The part I need some clarification is on the Return @Severity. Why would that not be Return @StartDate? As it is written it return the results of dbo.startdate().ALTER PROCEDURE GetStartDate(
@StartDate Datetime OUTPUT
)
AS
DECLARE
@Severity intSET @Severity = 0
IF @StartDate IS NULL
SET @StartDate = dbo.startdate(0)RETURN @Severity
DECALRE @StartDate DateTime
EXEC GetStartDate @StartDate OUTPUT
SELECT @StartDateThanks
Everett
Because @StartDate is the output parameter. In the beginning of the stored procedure it's declared as an output parameter and when executing the stored procedure, you are capturing the output parameter. Output parameters are explained in the documentation for Create Procedure - so it's not like it's easy to find.
CREATE PROCEDURE (Transact-SQL)
If you haven't worked with them much, you can find other posts and examples from other sites if you search on: output parameter in stored procedure
Sue
December 22, 2017 at 7:15 am
macbaze72 - Thursday, December 21, 2017 4:04 PMThis code works, but I don;t understand it. The part I need some clarification is on the Return @Severity. Why would that not be Return @StartDate? As it is written it return the results of dbo.startdate(). ...
Thanks
Everett
The RETURN value from any proc is always a single integer value. This is intended to be the status of the proc, i.e., 0 if successful, something else if not.
You don't need to, or want to, return OUTPUT parameters directly. For one thing, you could have many OUTPUT parameters. For another, SQL already "knows" it needs to return that value because of the "OUTPUT" designation.
SQL DBA,SQL Server MVP(07, 08, 09) "Money can't buy you happiness." Maybe so, but it can make your unhappiness a LOT more comfortable!
December 22, 2017 at 9:26 am
macbaze72 - Thursday, December 21, 2017 4:04 PMThis code works, but I don;t understand it. The part I need some clarification is on the Return @Severity. Why would that not be Return @StartDate? As it is written it return the results of dbo.startdate().ALTER PROCEDURE GetStartDate(
@StartDate Datetime OUTPUT
)
AS
DECLARE
@Severity intSET @Severity = 0
IF @StartDate IS NULL
SET @StartDate = dbo.startdate(0)RETURN @Severity
DECALRE @StartDate DateTime
EXEC GetStartDate @StartDate OUTPUT
SELECT @StartDateThanks
Everett
RETURN can only return integers and the RETURN in this code is basically useless someone considers a NULL to be a good return. Considering the spelling error in the code, I suspect a lot is missing. Please post the real code and post the code for the function that is called.
I also suspect that this should be a function rather than a stored procedure.
--Jeff Moden
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply