Can we store the result set of SP

  • Hi,

    I have a sub procedures , it contains

    two insertions & update query finall i have a select column1,column 2 from table name

    In main procedures am calling & i want o store the ,column 1 & column 2 in two temp variable ,

    Is it possible ?

  • Yes you are.

    You need to create temp table & use it to store the return resultset of stored procedure.

    CREATE TABLE #tempTable

    (Col1 NVARCHAR(MAX),

    Col2 NVARCHAR(MAX)

    )

    INSERT INTO #tempTable

    EXEC procSample;

    Hope sample will resolve your problem.

    Thanks

  • If you expect to select only one value for each column, I would recommed you to use OUT variables.

    However, if there can be multiple values, then the above solution is correct except one thing, use table variable instead of temp table.

    Thanks,

    Garima

  • Temp table is useful, if you want to supply the same table/data in the next calling procedure in the hierarchy.

    Thanks

  • THank u ...

  • Sorry for incon.

    If i tried with this format not working

    SELECT * INTO ##TEMP

    FROM

    T_SP_UPDATE_ITEM_DETAILS '139',30,'TB'

    Error

    Msg 102, Level 15, State 1, Line 3

    Incorrect syntax near '139'.

    please tell me

  • You cannot use 'select * into #temp from exec SPname'.

    You will have to create the temp table first and then use insert statement with execute SP to add the result set of SP to temp table.

    Thanks,

    Amit kulkarni

  • Instead of

    SELECT * INTO ##TEMP

    FROM

    T_SP_UPDATE_ITEM_DETAILS '139',30,'TB'

    write

    SELECT * INTO ##TEMP

    EXEC T_SP_UPDATE_ITEM_DETAILS '139',30,'TB'

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply