Using a temporary table

  • I've created a temporary table using select into statement, and called the table #Table1 (for example). But I can't get the syntax right to pull the information out of the table.

    Select * from [#Table1] doesn't work. How is a temporary table called in queries?

    Thanks.

  • it sounds like you are doing everything right...

    here's a basic example of a select into:

    select top 5 * into #Table1 from sysobjects

    Select * from [#Table1]

    that works fine on my machine...the only thing i can think of that might be a problem is if your server is case sensitive, and you create #table1 but reference #Table1

    can you post your actual exact query as an example?

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Your statement looks fine, What error are you getting?

    Are you able to post your entire query?

  • And, perhaps more importantly, are you selecting from the temporary table in the same query (or on the same connection) as you created it?

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • lallen (7/21/2008)


    I've created a temporary table using select into statement, and called the table #Table1 (for example). But I can't get the syntax right to pull the information out of the table.

    Select * from [#Table1] doesn't work. How is a temporary table called in queries?

    Thanks.

    Please post your code... we're just guessing here...

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • lallen (7/21/2008)

    --------------------------------------------------------------------------------

    I've created a temporary table using select into statement, and called the table #Table1 (for example). But I can't get the syntax right to pull the information out of the table.

    Select * from [#Table1] doesn't work. How is a temporary table called in queries?

    Thanks.

    I think, lallen has closed the current session and trying to get the temporary table again by using select statements. it seems like no issues in your query.

    but if you have closed the session, then the temporary table will not be available for you..

    Cheers!

    Sandy.

    --

  • Sandy (7/21/2008)


    lallen (7/21/2008)

    --------------------------------------------------------------------------------

    I've created a temporary table using select into statement, and called the table #Table1 (for example). But I can't get the syntax right to pull the information out of the table.

    Select * from [#Table1] doesn't work. How is a temporary table called in queries?

    Thanks.

    I think, lallen has closed the current session and trying to get the temporary table again by using select statements. it seems like no issues in your query.

    but if you have closed the session, then the temporary table will not be available for you..

    Cheers!

    Sandy.

    Sandy, temp tables are stored in temp database??

  • so, what you are trying to say??

    Cheers!

    Sandy.

    --

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

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