In testing output values from procs, why does the final select @TestValOut
return 0
instead of null
or an empty string?
I understand the correct way to do this is by using OUTPUT
parameters, so the question really becomes: Why is the datatype of the set value of @TestValOut
, at execution, an integer?
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'Custom.test') AND type in (N'P', N'PC'))
DROP PROCEDURE Custom.test
GO
CREATE PROCEDURE Custom.test (
@CurrentUserID INT = 1
)
As
Declare @TestValIn varchar(max)
select @TestValIn='asdf'
GO
BEGIN TRAN
Declare @TestValOut varchar(max)
set @TestValOut='ffff'
Exec @TestValOut=Custom.test @CurrentUserID=1
select @TestValOut
ROLLBACK