0

I'm able to query all the databases via How to run the same query on all the databases on an instance? but not sure how to run the query by matching a specific column and value.

example, assume column name is code. query + code='THBN'

Thanks.

Community
  • 1
  • 1

1 Answers1

0
EXECUTE sp_MSForEachDB 
'USE ?; 
SELECT * from table where code=''tbhn'''; 

you could also ignore system databases like below

EXECUTE sp_MSForEachDB 
'if db_id()>4
begin
SELECT * from table where code=''tbhn''
end'; 
TheGameiswar
  • 27,855
  • 8
  • 56
  • 94