Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2007
    Location
    Columbia SC
    Posts
    81

    Unanswered: how to check if columns exists in temporary table

    I am trying
    IF OBJECT_ID(''tempdb..#tempTable.Column'') IS NOT NULL



    But its returning me a null every time. Is there any other way to check if column exists in temporary table.

    Thanks in advance

  2. #2
    Join Date
    May 2007
    Posts
    49
    If exists (Select * from tempdb.information_schema.columns where table_name like '#tempLogin%' and column_name like 'column')
    Mihir Mehendale
    DB Team @ Clarion
    Clarion Technologies
    (SEI CMMI Level 3)
    Pune, India
    www.clariontechnologies.co.in
    www.vEmployee.com

  3. #3
    Join Date
    Nov 2010
    Posts
    1

    how to check if columns exists in temporary table

    If Exists (
    Select 1
    From tempdb.information_schema.Columns C (NoLock)
    Join tempdb.Sys.Objects O (NoLock)
    On (
    O.Object_Id = Object_Id(N'tempdb..#tempLogin')
    And O.Name = C.Table_Name
    )
    And C.Column_Name = 'myColumnName'
    )
    Begin
    Print 'Column Found.'
    End

  4. #4
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    too bad table_name did not have the spid as part of it's name


    Guess the bigger question is, what thread are you looking for????

    I'm guessing it's the one you're in?

    Code:
    CREATE TABLE #myTable99(Col1 int)
    GO
    
           SELECT *
    	  FROM tempdb.INFORMATION_SCHEMA.Columns
    	 WHERE Column_Name	= 'Col1'
    	     AND TABLE_NAME LIKE '#myTable99%'
    GO
    
    DROP TABLE #myTable99
    GO
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •