sql - Select qry to using 2 databases -
i have below query:
select --a.dateentered, --a.inventoryid, a.sku, a.qtyonhand, b.dateentered vdateentered, b.golive, b.dateonsite, b.costprice, --a.currentprice, m.name status, hrf.category, hrf.department, hrf.brandedob, hrf.division, hrf.fascia, (a.qtyonhand * b.costprice) cost_value, null item_quantity, null item, null season, hrf.company, (a.qtyonhand * b.currentprice) sellilng_value, b.merchandisingseason, b.costprice costprice_rp, b.currentprice, b.inventoryid, -- a.averageunitcost, -- a.averageunitcost rp_stk_averageunitcost, -- a.currentprice rp_stk_current_price, -- a.statusid, -- a.quantity_sign, (a.qtyonhand * b.costprice) cost_value_rp, (a.qtyonhand * b.averageunitcost) awc_value -- a.stockreconciliationid, -- a.averageunitcost, [dbo].[fc03qty] join dbo.inventory b on a.sku = b.sku left join (------hierarchy------- select ih.inventoryid, hry.category, hry.department, hry.brandedob, hry.division, hry.fascia, hry.company (select ihn.hierarchynodeid, ihn.inventoryid bm.inventoryhierarchynode ihn group ihn.hierarchynodeid, ihn.inventoryid) ih join (select g.categoryid, g.category, h.department, i.brandedob, j.division, k.fascia, l.company category g (nolock) join department h on g.departmentid = h.departmentid join brandedob (nolock) on h.brandedobid = i.brandedobid join division j (nolock) on i.divisionid = j.divisionid join fascia k (nolock) on j.fasciaid = k.fasciaid join company l (nolock) on k.companyid = l.companyid group g.categoryid, g.category, h.department, i.brandedob, j.division, k.fascia, l.company) hry on ih.hierarchynodeid = hry.categoryid group ih.inventoryid, hry.category, hry.department, hry.brandedob, hry.division, hry.fascia, hry.company) hrf on b.inventoryid = hrf.inventoryid join inventorystatus m (nolock) on b.statusid = m.statusid
it using 2 tables -
- [dbo].[fc03qty] a
and
- dbo.inventory b
that joined @ sku level.
[dbo].[fc03qty]
on scratch database , dbo.inventory
on reports database.
how can query use these tables if on 2 different db?
any advice received.
in sql server syntaxis tables [database name].[schema name].[table name]
so need this:
select a.*, b.* database1.dbo.table1 a, database2.dbo.table2 b
Comments
Post a Comment