Skip to content
Advertisement

How to find List Tables using columns value

I have 500+ tables in database. All tables have several columns. Among them Some tables have ‘CMDFLAG’ column and value of the columns may have ‘C’or’D’ or ‘M’.

My requirement is to find the list of tables where CMDFLAG is ‘C’or’D’ or ‘M’.

so on …

I can find list of tables these have CMDFLAG column using INFORMATION_SCHEMA.COLUMNS. But I Want to find list of tables where CMDFLAG columns have value ‘C’or’D’ or ‘M’.

I have gone through several questions but can’t fulfill my requirement. Moreover I want to use simple query not procedure.

Advertisement

Answer

Try this. I have to use dynamic query and temp tables as EXEC does not work for common table expressions.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement