Wednesday, 15 August 2007

Check exists column

You may want to check if a column exists before adding the column or performing some action on that column. Here is the clause to check column existence.

IF EXISTS (SELECT * FROM SysObjects O
INNER JOIN SysColumns C ON O.ID=C.ID
WHERE ObjectProperty(O.ID,'IsUserTable')=1
AND O.Name=
'TableName'
AND C.Name='ColumnName')

No comments:

Post a Comment