Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Finding a certain value from several tables

Author  Topic 

Petronas
Posting Yak Master

134 Posts

Posted - 2014-12-16 : 11:23:05
Hello ,

We have about 60 several tables with order id as a column in all of them . Every day I have to check if certain order id’s exist in the 60 tables. I just need to get the name of the table if it exists. Is there a way to dynamically keep changing the name of the table instead of having all 45 tables in the script?

Thanks for your help,
Petronas

sz1
Aged Yak Warrior

555 Posts

Posted - 2014-12-16 : 11:27:12
You can try something like this, change the string to what you want to find and it will return the table name(s) where its found.

SELECT COLUMN_NAME, TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME LIKE '%Order_RecID%'

We are the creators of our own reality!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2014-12-22 : 04:31:09
See if this helps
http://beyondrelational.com/modules/2/blogs/70/posts/10883/search-a-value-in-character-column-of-all-tables.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -