While trying OUTPUT variable, and assigning the variable with itself my proc returns null. The value is correctly assigning in the OUTPUT variable and works if I don't provide the optional output. Please check the below code
ALTER PROC [DBO].TEST (
@IN NVARCHAR(10) ,
@OUT NVARCHAR(MAX) = 'JAMES' OUTPUT)
AS
BEGIN
SET @OUT = @OUT + '-' + @IN
PRINT @OUT
END
---This Works
EXEC TEST 'BOND'
--OUTPUT : JASMES-BOND
---This doesn't Work
DECLARE @OUT1 NVARCHAR(MAX)
EXEC TEST 'BOND', @OUT1 OUTPUT
PRINT @OUT1
-- No Error, No Output
If I change the statement SET @OUT = @OUT + '-' + @IN to SET @OUT = '-' + @IN the code gives output, but that's not my desired output. Please help me