我想为Kit规范库存创建报告,但在创建时,我看到存储有关Stock和Non-stock的表不在一个表中。在报告中我想使用那种类型库存。如下图所示:
这是我使用的UNION
SELECT a.CompanyID,a.KitInventoryID,a.RevisionID,a.CompInventoryID,a.DfltCompQty,a.UOM,a.MinCompQty,a.MaxCompQty,d.InventoryCD,d.Descr
FROM dbo.INKitSpecStkDet a
INNER JOIN dbo.InventoryItem d ON a.CompInventoryID=d.InventoryID
UNION All
SELECT b.CompanyID,b.KitInventoryID,b.RevisionID,b.CompInventoryID,b.DfltCompQty,b.UOM,b.MinCompQty,b.MaxCompQty,c.InventoryCD,c.Descr
FROM dbo.INKitSpecNonStkDet b
INNER JOIN dbo.InventoryItem c ON b.KitInventoryID=c.InventoryID
答案 0 :(得分:0)
希望这就是你想要的。
create table #TableA
(
ID varchar(10),
Name varchar(20),
Type varchar(10),
Value int
)
create table #TableB
(
ID varchar(10),
Name varchar(20),
Type varchar(10),
Value int
)
insert into #TableA values ('0001','ItemA','A',100)
insert into #TableA values ('0002','ItemB','A',100)
insert into #TableA values ('0003','ItemC','A',100)
insert into #TableB values ('0001','ItemA','B',100)
insert into #TableB values ('0002','ItemB','B',100)
insert into #TableB values ('0003','ItemC','B',100)
insert into #TableB values ('0004','ItemD','B',100)
insert into #TableB values ('0005','ItemE','B',100)
select * from #TableA
union
select * from #TableB where name not in(select Name from #TableA)
看看这是否有帮助
SELECT COALESCE(#TableA.ID, #TableB.ID) AS ID,
COALESCE(#TableA.Name, #TableB.Name)AS Name,COALESCE(#TableA.Type, #TableB.Type)AS Type,COALESCE(#TableA.Value, #TableB.Value)AS Value
FROM #TableA
FULL OUTER JOIN #TableB
ON #TableB.ID = #TableA.ID