February 4, 2013 at 11:38 am
Hi All,
Looking to run the following select statement across all databases. Not having any luck after researching.
select * from t_payers where pay_name = 'Name of Payer'
Any help would be appreciated!
February 4, 2013 at 11:46 am
sp_msForEachDb
'If EXISTS(SELECT 1 FROM [?].sys.tables WHERE name = ''t_payers'')
select [?] As DbName,* from [?].dbo.t_payers where pay_name = ''Name of Payer''; '
Lowell
February 4, 2013 at 11:50 am
Thanks. After running that I am getting column name errors -
Msg 207, Level 16, State 1, Line 2
Invalid column name 'DB1'.
Msg 207, Level 16, State 1, Line 2
Invalid column name 'DB2'.
Any idea?
February 4, 2013 at 11:54 am
oops sorry; the first quesiton mark should be in quotes:
sp_msForEachDb
'If EXISTS(SELECT 1 FROM [?].sys.tables WHERE name = ''t_payers'')
select ''[?]'' As DbName,* from [?].dbo.t_payers where pay_name = ''Name of Payer''; '
Lowell
February 4, 2013 at 12:03 pm
Awesome. Thanks! How do I give you rep? 🙂
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply