I need to UNION
data from tables with the same name in multiple databases. All databases have the same prefix: CDNXL_
(NAME OF DB)
How would I execute this query against more than one database at at time?
SELECT
prac_id,
prac_name,
prace_surname,
prac_IDcard,
prac_workplace
From prac_nag.CDNXL_ (NAME OF DB)
where prac_IDcard = @parameter
Can this be done with 'IF'
or 'WHILE'
?
— Edit
Now I can see my mistake.
I have got 46 Databases with prefix CDNXL_ but one is DB with CDNXL_Configuration, and doesn't have got table was I wanna. How can I skip/ignore this DB?
Best Answer
No need to use cursor or undocumented methods. You can just use dynamic tsql.