Stored procedure returns 0 instead of value
2 There is a stored procedure that can return top 1 result as USE [DB] GO ..... CREATE PROCEDURE [dbo].[GET] (@in VARCHAR(10), @Out VARCHAR(10) OUTPUT) AS SELECT top 1 @Out = tab.Col FROM table tab RETURN GO When I call it in main query DECLARE @output VARCHAR(10) DECLARE @in VARCHAR(10) DECLARE @Out VARCHAR(10) EXECUTE dbo.GET @in = 'table', @Out = @output It prints @output as 0; but if I do EXECUTE dbo.GET @in = 'table', @Out = @Out And print @out , I get the correct value. Why could this happen? I did pass output @Out to pre-defined variable @output sql sql-server rdbms share | improve this question edited Nov 13 '18 at 3:02 NewPy asked Nov 12 '18 at 3:35 NewPy NewPy 127 6 Please refer codeproject.com/articles/794765/… – Sanal Sunny Nov 12 '18 at 4:08 3 Procedural code is highly vendor-specific - so please add a tag to specify whether you're using mysql , postgresql ...