Merge 2 tables from different databases no matching fields into a temp table on SQL Server -


i'm working on project , i'm stumped. have 2 websites take orders. databases on same server. each website stores order data tables in separate databases. primary site uses "dbo.orders", table used give data our aspdotnetstorefront backend. our sales people use interface review orders. secondary site uses"dbo.orders", table used store orders. second site's orders not accessible on aspdotnetstorefront. job merge orders secondary site table primary site orders can seen on aspdotnetstorefront backend orders primary site. have create identifier when viewed sales people know site order from. think creating temporary table , maybe outer join or merge? problem tables have no matching fields. suggestions appreciated.

you can use union all combine records

select 1 siteid,         * -- common fields   database1.dbo.orders union  select 2 siteid,         * -- common fields   database2.dbo.orders 

fields in database2.dbo.orders have same type field in database2.dbo.orders. example, following not work.

select 1 siteid,        customername -- varchar union select 2 siteid,        orderdate    -- datetime 

add fillers if need to, if column exists in 1 table , need include in query.

select 1 siteid,        customername customername,        null orderdate  -- filler match orderdate   database1.dbo.orders union select 2 siteid,        '',  -- filler match customername        orderdate   database1.dbo.orders 

to create temp table can add into [table] syntax first select. example using ordernumber ordid fields

select 1 siteid,         ordernumber   #temp -- create temp table hold rows generated union   database1.dbo.orders union  select 2 siteid,         ordid  -- appear in second column [ordernumber]   database2.dbo.orders 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -