TSQL - Getting the value from a stored procedure into a variable
(Test1 VARCHAR(20))INSERT INTO MyTest
(Test1)
VALUES
('Hello')CREATE PROCEDURE GetTest
AS
BEGIN
SELECT Test1
FROM MyTest
ENDDECLARE @tabCaptureTheResults TABLE (Data VARCHAR(20))INSERT @tabCaptureTheResults
EXEC GetTestThis results in:
Server: Msg 197, Level 15, State 1, Line 4
EXECUTE cannot be used as a source when inserting into a table variable.CREATE TABLE #CaptureTheResults (Data VARCHAR(20))INSERT #CaptureTheResults
EXEC GetTestSELECT * FROM #CaptureTheResultsThis results in 'Hello' being returned, exactly as required.
Whilst this works, it isn't exactly going to be efficient. Anyone know of any better ways of doing this within TSQL?UPDATE:
As of SQL 2005 both cases seem to work - Hurrah!