StoredProcedure With Temptable

  • Hi

    I am Wrting a StoredProcedure ,But i use this stored procedures output into a temp table  for using this output into another Storedprocedure,

     

     

     

  • If you are going to have another SP use the data from this SP's temp table then you need to use ##tablename and not #tablename.  The ## is available for anyone and the # is only available to the CURRENT SP.  OR...  you could dump the data into a REAL table created in tempdb and then DROP it afterwards..  Just a couple of different approachs



    Good Hunting!

    AJ Ahrens


    webmaster@kritter.net

  • Ok

    But i Use This Command It shows Error

    What command i use for this

    exec <storedprocedure name> #temptablename

    select * into #temptablename from <storedprocedure name>

    both commands are failed to process

     

     

     

  • try the following

    1.  Build the ##temptable information or real table with data inside the 1st sp

    2.  Call the 2nd sp that uses the table from sp 1

    EXEC sp1

    EXEC sp2



    Good Hunting!

    AJ Ahrens


    webmaster@kritter.net

  • Ok Is it Possible to Store The Output of Sp into Pernment table

     

  • Yes,

    Insert [#][#]Table Exec Proc

    BUT, the table must already exist and have the same structure as the output of the Proc.

    /rockmoose


    You must unlearn what You have learnt

  • Try this:

    Insert #temptablename

    exec <storedprocedure name>

     

    This will fill your temptable with results from the sp


    Regards,

    Anders Dæmroen
    epsilon.no

  • Yes, but the table must already exist..

    So you have to create it prior to: insert <table> exec <proc>

    /rockmoose


    You must unlearn what You have learnt

  • Hi Thanks its Working

    But  i have to create the #Temp table Structure externally what o/p used in the sp i have used.

    its not create the temp table dynamically while executing the sp

     

     

  • Why do you have to create the #Temp table Structure externally?

    What are You trying to accomplish?

    /rockmoose


    You must unlearn what You have learnt

  • insert #freebaltb EXEC GET_IVRSCRIPWISEBALANCE 888888888

    i am executing this query  i m getting this kind of error

    Server: Msg 208, Level 16, State 1, Line 1

    Invalid object name '#freebaltb'.

    can u tell me wht is the reason

  • You would have to do:

    create table #freebaltb( ... table definition here ... )

    insert #freebaltb EXEC GET_IVRSCRIPWISEBALANCE 888888888

    /rockmoose


    You must unlearn what You have learnt

Viewing 12 posts - 1 through 11 (of 11 total)

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