question

John 3 1 avatar image
John 3 1 asked

Combine contents of tables from several db into one view or sp

I would like to combine the contents of tables from different customer databases into one view or sp so I could get a master list. All the tables have same fieldnames, just the data is for different for each db. I tried listing the SELECT statements into a sp but it pulled separate rows for each db. How do I combine so I only see one master list?
thanks,

John

t-sqlstored-proceduresviewcross-database
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Kev Riley avatar image
Kev Riley answered

Union

place a UNION ALL operator between each of your select statements i.e.

select col1, col2, col3 from server1.db1.dbo.table
union all
select col1, col2, col3 from server2.db2.dbo.table
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.