Friday, March 9, 2012

Expected value not being set.

Hi,
I'm trying to set the value of the variable @.prvYearMonth thru this sp. In the query analyzer I execute the following code to the see the results of my 'CabsSchedule_GetPrevYearMonth' SP, but the only see "The Command(s) completed successfully in the result. What am I missing??

Thanks in advance


CREATE PROCEDURE CabsSchedule_GetPrevYearMonth
(
@.prvYearMonth int OUTPUT
)

AS
BEGIN
SET @.prvYearMonth = (SELECT MAX(YearMonth) FROM CabsSchedule)
END
GO

DECLARE @.PrvYearMonth int
EXEC CabsSchedule_GetPrevYearMonth @.PrevYearMonth OUTPUT

SELECT @.PrevYearMonth|||Hi Doug,
Thanks for the reply. It was exactly what I was looking for. Now, I had modified my SP so that the same OUTPUt parameter @.PrvYearMonth is used for 2 different purposes. if it is set to 0 then it follows the logic in my IF statement in my SP and if I pass any other value than 0 it follows the logic in the ELSE bloch of my SP. How do I test this in the query analyzer??

Thanks,|||DECLARE @.PrvYearMonth int
SET @.PrvYearMonth=0
EXEC CabsSchedule_GetPrevYearMonth @.PrevYearMonth OUTPUT

SELECT @.PrevYearMonth

That said, it is not a great idea to have a variable that means different things at different times. Personally, I would add an additional variable used for your IF testing.

No comments:

Post a Comment