0

I have two different system databases: Management_Reporting and MPS.

I need some tables from Management_Reporting.dbo.TreatmentSummary and MPS.dbo.BloodTest.

I tried UNION ALL, but there are different numbers of fields within dbo.TreatmentSummary and dbo.BloodTest.

How do I query another system database from another?

I can easily query one database from another within the same system database, but this one eludes me.

Replies to replies: @siggemannen apologies - I used the right term in the next line... was concentrating on trying to explain the relationships - whoops!

@Charlieface I had expected results in my original post, but they were edited out by someone else. I have Management_Reporting.dbo.TreatmentSummary which contains columns like PatientID, DrugRegime etc, and then MPS.dbo.BloodTest containing PatientId and blood results like FSH, E2, P4 etc. I need to query these combined results. I don't think work would like me posting sample data sorry.

@ThomA I'll look into that, thank you

edited again to further clarify:

@ThomA these are contained databases... do you have any ideas or pointers, please?

JMo
  • 1
  • 1
  • Sample data and expected results would help immensely – Charlieface Mar 26 '23 at 01:21
  • Can you not use 3 part naming or are these contained databases? – Thom A Mar 26 '23 at 09:08
  • You mean you need some fields (not tables)? If you want tables from different database, just append the database name in your FROM, like: SELECT field1, field2 FROM DatabaseName.dbo.Tablename t. If you need to join then, it's the same, just append the database name – siggemannen Mar 26 '23 at 13:45
  • I don't understand the question, if you need a query, you should show the tables, the fields and the select you tried. If you need to query both databases in a link, you should ask at dba.stackexchange.com – Leandro Bardelli Mar 26 '23 at 21:10
  • @LeandroBardelli these are contained databases – JMo Mar 26 '23 at 22:45

0 Answers0