• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

You are not logged in or you do not have permission to access this page. This could be due to one of several reasons:

  • You are not logged in. If you are already registered, fill in the form below to log in, or follow the "Sign Up" link to register a new account.
  • You may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
  • If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.

Previously on "SQL 2005 - check if Temp Table exists"

Collapse

  • wxman
    replied
    Great I have got it workling - it was actually the double dot .. between the tempDB and the table name that was scuppering me

    Thank's to all that suggest fixes

    Leave a comment:


  • Spacecadet
    replied
    Originally posted by Sir_Edward_Matheson View Post
    @Spacecadet
    You should be using information_schema.tables and not sysobjects
    you are right, i was just messing around with something though

    Leave a comment:


  • Sir_Edward_Matheson
    replied
    if object_id('tempdb..#temptbl', 'u') is not null
    ...
    @Spacecadet
    You should be using information_schema.tables and not sysobjects
    Last edited by Sir_Edward_Matheson; 15 April 2008, 13:18.

    Leave a comment:


  • Spacecadet
    replied
    spooky

    I was experimenting around and wrote this bit of SQL not more than an hour ago:
    Code:
    select * into #temp1 
    from  [add your source objects here]
    where 1=2 
    
    select * from tempdb.dbo.syscolumns
    where id = (select id from tempdb.dbo.sysobjects where name like '#temp1%')
    
    drop table #temp1

    Leave a comment:


  • hyperD
    replied
    Quick reply, not checked - hope it helps

    USE PUBS
    GO

    CREATE TABLE #some_temp_name(id INT)
    GO

    USE TEMPDB
    GO

    SELECT OBJECT_NAME(OBJECT_ID('#some_temp_name'))

    USE PUBS
    GO


    IF OBJECT_ID('tempdb..#some_temp_name') IS NOT NULL
    PRINT '#some_temp_name exists.'
    ELSE
    PRINT '#some_temp_name does not exist.'
    Last edited by hyperD; 15 April 2008, 12:28.

    Leave a comment:


  • wxman
    started a topic SQL 2005 - check if Temp Table exists

    SQL 2005 - check if Temp Table exists

    SQL2005 SP2

    Suggections on how I check if a temp table (#messages_temp) exists in a database?

    something like...
    if exists(#messages_temp)
    BEGIN
    DROP #messages_temp
    END
    ELSE
    BEGIN
    CREATE #messages_temp
    END
Working...
X