Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Store result from a stored procedure into a var

Author  Topic 

rdiazc
Starting Member

2 Posts

Posted - 2008-01-18 : 15:58:09
Hi:

I just need assign the result of a stored procedure that return a set of rows into a variable or temporal table:

<code>
CREATE TABLE #ArticlesTemp(
[IdArticulo] [int] NOT NULL,
[Cod] [nvarchar](50) COLLATE Modern_Spanish_CI_AS NOT NULL,
[CodPropio] [nvarchar](50) COLLATE Modern_Spanish_CI_AS NOT NULL,
.
.
.
[DF_TArticulos_VerEnWeb] DEFAULT ((1))
)

DECLARE @Query NVARCHAR(250);
SELECT @Query = N'SELECT ROW_NUMBER() OVER (ORDER BY [IdArticulo] ASC) AS Row, [IdArticulo], [Cod], [CodPropio], [Descripcion], [CodDivision], [CodFami], [CodSubFami], [VerEnWeb] FROM [TArticulos]WHERE [VerEnWeb]=1';

--I know the next line is incorrect but how can I do this?????
SELECT #Articles = EXEC sp_executesql @Query;

</code>

Thanks in advanced

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-01-18 : 16:07:47
Try this:

Insert #ArticlesTemp
Exec sp_executesql @Query


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

rdiazc
Starting Member

2 Posts

Posted - 2008-01-18 : 17:23:49
Thank you very much Harsh Athalye!!!
That's the correct way. You have my vote!!
Go to Top of Page
   

- Advertisement -