1

I need to find if a column exists using an IF condition.

If it does not exist add the column.

If it does exist then update the column.

How do I check if the column exists in a particular table in a database in SQL Server 2008?

ChrisM
  • 1,576
  • 6
  • 18
  • 29

1 Answers1

0

Try this:

SELECT t.name as TabName
    ,c.name as ColName
FROM sys.columns c 
INNER JOIN sys.tables t on c.object_id = t.object_id
WHERE c.name like '%COLUMN_NAME%'
    AND t.name = 'TABLE_NAME'
Nigel Ren
  • 56,122
  • 11
  • 43
  • 55
soser
  • 1
  • 1