简体   繁体   中英

Stored Procedure Output

I've got two stored procedures:

SP1

CREATE PROCEDURE GetAge

@Birthday datetime,
@BirthDayAge INT OUTPUT

AS

SELECT @BirthDayAge = YEAR(GETDATE()-DATEPART(dy, @Birthday) + 1)-YEAR(@Birthday);

SP2

CREATE PROCEDURE AgeProc

@Age int

AS

DECLARE @BirthDayAge INT;
EXEC GetAge @Age, @BirthDayAge OUTPUT

SELECT ... FROM ... WHERE @BirthdayAge  = @Age;

For some reason or other, no results are being returned in the second procedure when tested. Am I doing something wrong in either of the stored procedures?

 WHERE @BirthdayAge  = @Age;

you are comparing 2 variables.

Shouldnt one of this be a table column?

also, you are passing an integer to a datetime, that may cause issues

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM