Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set a SP return value to a variable in SQL Server

I have a sproc that returns a single line and column with a text, I need to set this text to a variable, something like:

declare @bla varchar(100)
select @bla = sp_Name 9999, 99989999, 'A', 'S', null

but of course, this code doesn't work...

thanks!

like image 293
Bruno Avatar asked Oct 17 '08 11:10

Bruno


1 Answers

If you are unable to change the stored procedure, another solution would be to define a temporary table, and insert the results into that

DECLARE @Output VARCHAR(100)

CREATE TABLE #tmpTable
(
    OutputValue VARCHAR(100)
)
INSERT INTO #tmpTable (OutputValue)
EXEC dbo.sp_name 9999, 99989999, 'A', 'S', null

SELECT
    @Output = OutputValue
FROM 
    #tmpTable

DROP TABLE #tmpTable
like image 122
Tim C Avatar answered Oct 20 '22 05:10

Tim C