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.
Author |
Topic |
QuietRiot
Yak Posting Veteran
67 Posts |
Posted - 2008-01-14 : 13:39:28
|
say I have a select statementSelect FundId, AccountNumber, InceptionDate from FundInfo where FundID = '6600'now I want to run this for all databases that begin with AAA. and join together. |
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2008-01-14 : 14:03:47
|
One (quick, non-automated) way would be to just geneate the code using a SELECT from sysDatabases and paste the ouput into a new window. The only reason to do it like this is to save a little typeing. (Just don't include the final "UNION ALL")select'Select FundId, AccountNumber, InceptionDate from ' + db_name(dbid) + '..FundInfo where FundID = ''6600''union all'from master..sysdatabaseswhere name like 'AAA%' Be One with the OptimizerTG |
 |
|
QuietRiot
Yak Posting Veteran
67 Posts |
Posted - 2008-01-14 : 14:14:47
|
it didn't seem to do anythingthe output just says (no column name) nothing else |
 |
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2008-01-14 : 14:25:26
|
Then you don't have any databases that begin with 'AAA%'try commenting out the WHERE clause to see if you get results.EDIT:also, put your output in "text" mode, rather than "grid" mode.<control+T>Be One with the OptimizerTG |
 |
|
QuietRiot
Yak Posting Veteran
67 Posts |
Posted - 2008-01-14 : 14:37:53
|
I got it to workforgot the % after ABC.. :(definitely easier. I have about 200 databases.this will work for now. Thank you!!If anyone has any other methods let me know. I luv learning. |
 |
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2008-01-14 : 14:56:15
|
I've never tried to UNION ALL 200 statements. If it blows out some sql server limitation let us know.Be One with the OptimizerTG |
 |
|
|
|
|