Accessing temporary table from stored procedure

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sonysunny
    New Member
    • Feb 2008
    • 6

    Accessing temporary table from stored procedure

    Hai,

    I have a temporary table created in a stored procedure.How can i access that temporary table from another stored procedure.

    thanks in advance.
  • amitpatel66
    Recognized Expert Top Contributor
    • Mar 2007
    • 2358

    #2
    Originally posted by sonysunny
    Hai,

    I have a temporary table created in a stored procedure.How can i access that temporary table from another stored procedure.

    thanks in advance.
    If the temporary table created by stored procedure one is not dropped with in the procedure, then you can access that table using a simple select statement in second procedure. But make sure you execute procedure 1 so that the table gets created and then execute procedure 2 to access that table.

    But once the table is created and you run procedure1 again, it will error out saying the table already exists. So make sure about your work around and requirement.

    Comment

    • ck9663
      Recognized Expert Specialist
      • Jun 2007
      • 2878

      #3
      Here's more about temporary table. Just search the word Temporary Table and there are explanations of various kinds.

      -- CK

      Comment

      • Brad Orders
        New Member
        • Feb 2008
        • 21

        #4
        Hi SonySunny

        It sounds like you have a scope issue. If you always call the second stored procedure after the first stored procedure, then you should call the second stored procedure from within the first stored procedure using the "EXEC" command. Then the second stored procedure will be able to "see" the temporary table.

        However, if the first and second stored procedures do not always follow each other, I would suggest that you don't use a temporary table. Use a "real" database table. Then you won't have problems accessing it from another stored procedure.

        HTH

        Brad

        Comment

        Working...