Вы можете объединиться влево со всеми 8 таблицами элементов и представить их без сводки.
При условии, что базовая таблица равна MyBaseTable
, а у вас есть еще 8 таблиц Item1 ... Item8
.
Select
[Id],
[ItemOrdinal],
[Amount],
[Qty],
Item1.Amt as Item1Amt,
Item1.Qty as Item1Qty,
Item2.Amt as Item2Amt,
Item2.Qty as Item2Qty,
Item3.Amt as Item3Amt,
Item3.Qty as Item3Qty,
Item4.Amt as Item4Amt,
Item4.Qty as Item4Qty,
Item5.Amt as Item5Amt,
Item5.Qty as Item5Qty,
Item6.Amt as Item6Amt,
Item6.Qty as Item6Qty,
Item7.Amt as Item7Amt,
Item7.Qty as Item7Qty,
Item8.Amt as Item8Amt,
Item8.Qty as Item8Qty
From MyBaseTable as Base
Left Join Item1 on Item1.[ItemOrdinal] = Base.[ItemOrdinal]
Left Join Item2 on Item2.[ItemOrdinal] = Base.[ItemOrdinal]
Left Join Item3 on Item3.[ItemOrdinal] = Base.[ItemOrdinal]
Left Join Item4 on Item4.[ItemOrdinal] = Base.[ItemOrdinal]
Left Join Item5 on Item5.[ItemOrdinal] = Base.[ItemOrdinal]
Left Join Item6 on Item6.[ItemOrdinal] = Base.[ItemOrdinal]
Left Join Item7 on Item7.[ItemOrdinal] = Base.[ItemOrdinal]
Left Join Item8 on Item8.[ItemOrdinal] = Base.[ItemOrdinal]
Новый ответ на основе новой скрипки SQL Скрипка :
Select
Base.[Id],
Base.[ItemOrdinal],
Base.[ItemDesc],
Base.[ItemAmt],
Base.[ItemQty],
Item3.[ItemAmt] as Item3Amt,
Item3.[ItemQty] as Item3Qty,
Item4.[ItemAmt] as Item4Amt,
Item4.[ItemQty] as Item4Qty
From [dbo].[Tbl_2] as Base
Left Join Tbl_3 as Item3 on Item3.[ItemOrdinal] = Base.[ItemOrdinal]
Left Join Tbl_4 as Item4 on Item4.[ItemOrdinal] = Base.[ItemOrdinal]