Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 how to check if column exists in temporary table

Author  Topic 

musman
Starting Member

17 Posts

Posted - 2008-06-13 : 09:09:21


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.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-06-13 : 09:13:03
[code]IF EXISTS (SELECT * FROM TempDB.INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = 'Column' AND TABLE_NAME LIKE '#TempTable%')
PRINT Column exists'
ELSE
PRINT Column doesn''t exists'[/code]


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

musman
Starting Member

17 Posts

Posted - 2008-06-13 : 09:16:35
I need to check columns not table coz i am writing a dynamic sql. and need to confirm if columns exist and then enter data in that column.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-06-13 : 09:37:06
Yes. And my query does that.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

musman
Starting Member

17 Posts

Posted - 2008-06-13 : 09:57:06
Exactly it does that. my bad i didnt see the whole line. Well what if I wanna use this for multiple columns. I tried putting AND COLUMN_Name='Col2' but couldnt do that. Any thoughts.

Thanks for your help tho.
Go to Top of Page
   

- Advertisement -