Thursday, March 8, 2012

[QA] Run 1 query on multiple db's

Hello, could someone help me on this one.
Situation:
Multiple databases with same tables etc. (12 monthly archiving data db's).
In Query Analyzer, can I run 1 query same table on all my 12 db's which
would output 1 result?
Let say:
USE dbjanuari
select firstname from employees
where firstname = 'tom'
but instead dbjanuari, also dbfebruari, dbmarch etc.
Sorry for this 'noobly' question.
Rgds 2 all
T.
SELECT firstname from dbjanuari.dbo.employees where firstname = 'tom'
UNION ALL
SELECT firstname from dbfebruari.dbo.employees where firstname = 'tom'
UNION ALL
SELECT firstname from dbmarch.dbo.employees where firstname = 'tom'
|||"bert" <bertcord@.gmail.com> wrote in message
news:1107275120.849338.6340@.c13g2000cwb.googlegrou ps.com...
> SELECT firstname from dbjanuari.dbo.employees where firstname = 'tom'
> UNION ALL
> SELECT firstname from dbfebruari.dbo.employees where firstname = 'tom'
> UNION ALL
> SELECT firstname from dbmarch.dbo.employees where firstname = 'tom'
>
Ok, thank you Bert for helping me out!!
Rgds,
T.

No comments:

Post a Comment