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?

1
  • You can use IF COL_LENGTH('TABLENAME','COLUMNNAME') IS NOT NULL PRINT 'Existed' Commented May 20, 2018 at 19:30

1 Answer 1

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' 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.