Reputation: 699
I have 6 different tables, say: dbo.One, dbo.Two, dbo.Three,.....,dbo.Six
I want to check if a certain string (ex: "CatWS_Energy_CB") exists in ANY of the columns of the 6 different tables (This string is not the whole column name but is contained in the column name). Is there a way to do this? I'm trying to do an if statement in SQL but I'm not quite sure how to approach this first part.
Any help will be appreciated!
Upvotes: 1
Views: 1788
Reputation: 453608
Based on discussion in the comments I think this is what you need.
SELECT Object_name(object_id, Db_id('Catastrophe'))
FROM Catastrophe.sys.columns
WHERE name LIKE '%CatWS_Energy_CB%'
AND object_id IN ( Object_id('Catastrophe.dbo.One'),
Object_id('Catastrophe.dbo.Two'),
Object_id('Catastrophe.dbo.Three') )
Upvotes: 1