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,518
  • 6
  • 17
  • 27

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
  • 53,991
  • 11
  • 38
  • 52
soser
  • 1
  • 1