https://blog.sqlauthority.com/2013/09/26/sql-server-select-columns-from-stored-procedure-resultset/
First we will create a sample stored procedure.
1 2 3 4 5 6 | CREATE PROCEDURE SampleSPASSELECT 1 AS Col1, 2 AS Col2UNIONSELECT 11, 22GO |
Now we will create a table where we will temporarily store the result set of stored procedures. We will be using INSERT INTO and EXEC command to retrieve the values and insert into temporary table.
1 2 3 4 5 | CREATE TABLE #TempTable (Col1 INT, Col2 INT)GOINSERT INTO #TempTableEXEC SampleSPGO |
Next we will retrieve our data from stored procedure.
1 2 3 | SELECT *FROM #TempTableGO |
Finally we will clean up all the objects which we have created.
1 2 3 | DROP TABLE #TempTableDROP PROCEDURE SampleSPGO |
Let me know if you want me to share such back to basic tips.
No hay comentarios:
Publicar un comentario