query with join across multiple databases-syntax error

后端 未结 3 1781
醉酒成梦
醉酒成梦 2021-01-25 19:45

I have 2 databases namely db1,db2. I need a query that fetch the data from these dbs(db1,db2) which have inturn 2 tables(concessions,invoicing) each.

In db1.concessions

3条回答
  •  花落未央
    2021-01-25 20:15

    select * from(
    SELECT a.concession as db1_CON_NUMBER FROM BABMwork6_5_3108.dbo.concessions as a  
            WHERE (a.manuell_archive_delete! = 'Delete' OR  a.manuell_archive_delete IS NULL) 
    UNION SELECT b.[Concession Number] as db1_CON_NUMBER  FROM BABMwork6_5_3108.dbo.invoicing as b) as tbl1 
    INNER JOIN 
    (SELECT c.concession as db2_CON_NUMBER FROM BABMwork6_6_2909.dbo.concessions as c  
            WHERE (c.manuell_archive_delete! = 'Delete' OR  c.manuell_archive_delete IS NULL) 
    UNION SELECT d.[Concession Number] as db2_CON_NUMBER  FROM BABMwork6_6_2909.dbo.invoicing as d ) as tbl2
    ON tbl1.[db1_CON_NUMBER] = tbl2.[db2_CON_NUMBER]
    

提交回复
热议问题