Reputation: 638
I have a stored procedure which returns an integer value.
Can I return a varchar instead of int ? Is there any way to return the varchar value to the calling procedures?
Upvotes: 1
Views: 5084
Reputation: 847
It really escapes me why everywhere I turn nobody mentios the simple fact that you can just declare it like this
CREATE SP_foo
AS
BEGIN
RETURN 'muajaja'
END
GO
Than you can call something like this:
DECLARE @r varchar(255)
EXEC @r = SP_foo
I don't know if NOBODY mentions it like this because is probably not part of the T-SQL standard per-se? Even the MS docs says something weird:
RETURN [ integer_expression ]
integer_expression Is the integer value that is returned. Stored procedures can return an integer value to a calling procedure or an application
But hey! as long as it works, right?
Upvotes: 0
Reputation: 41539
You've got a couple of options:
Either use output parameters:
http://msdn.microsoft.com/en-us/library/ms378108.aspx
or just select
the varchar value at the end to return the data in a one-line/one-field table.
Upvotes: 3