Это может помочь
CREATE TABLE [dbo].[SampleOrders](
[Id] [int] IDENTITY(1,1) NOT NULL,
[ProductId] [int] NULL,
[OrderDate] [datetime] NULL,
[CustomerId] [int] NULL,
[Quantity] [float] NULL,
CONSTRAINT [PK_SampleOrders] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[SampleStock](
[Id] [int] IDENTITY(1,1) NOT NULL,
[ProductId] [int] NULL,
[Quantity] [float] NULL,
[Status] [int] NULL,
[StockDate] [datetime] NULL,
CONSTRAINT [PK_SampleStock] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
INSERT INTO SampleOrders(ProductId,OrderDate,CustomerId,Quantity) VALUES(1001,'2019-06-10 00:00:00.000', 1, 10)
INSERT INTO SampleOrders(ProductId,OrderDate,CustomerId,Quantity) VALUES(1001,'2019-06-01 00:00:00.000', 1, 20)
INSERT INTO SampleOrders(ProductId,OrderDate,CustomerId,Quantity) VALUES(1002,'2019-06-02 00:00:00.000', 2, 2 )
INSERT INTO SampleOrders(ProductId,OrderDate,CustomerId,Quantity) VALUES(1002,'2019-06-20 00:00:00.000', 2, 4 )
INSERT INTO SampleOrders(ProductId,OrderDate,CustomerId,Quantity) VALUES(1001,'2019-05-20 00:00:00.000', 1, 6 )
INSERT INTO SampleOrders(ProductId,OrderDate,CustomerId,Quantity) VALUES(1002,'2019-05-22 00:00:00.000', 1, 14)
GO
INSERT INTO SampleStock(ProductId,Quantity,Status,StockDate) VALUES (1001,20,1,'2019-06-10 00:00:00.000')
INSERT INTO SampleStock(ProductId,Quantity,Status,StockDate) VALUES (1002,10,1,'2019-06-12 00:00:00.000')
INSERT INTO SampleStock(ProductId,Quantity,Status,StockDate) VALUES (1001,10,1,'2019-05-02 00:00:00.000')
INSERT INTO SampleStock(ProductId,Quantity,Status,StockDate) VALUES (1002,6 ,2,'2019-05-20 00:00:00.000')
INSERT INTO SampleStock(ProductId,Quantity,Status,StockDate) VALUES (1003,4 ,2,'2019-05-20 00:00:00.000')
GO
SELECT * FROM SampleOrders
SELECT * FROM SampleStock
GO
-- DROP TABLE #MonthlySales
SELECT Product
,January as JanuarySales
,February as FebruarySales
,March as MarchSales
,April as AprilSales
,May as MaySales
,June as JuneSales
,July as JulySales
,August as AugustSales
,September as SeptemberSales
,October as OctoberSales
,November as NovemberSales
,December as DecemberSales
INTO #MonthlySales
FROM (SELECT m.ProductId [Product],
DATENAME(MONTH, m.OrderDate) [Month],
SUM(ISNULL(M.Quantity, 0)) [Sales]
FROM SampleOrders m
GROUP BY m.ProductId,
DATENAME(MONTH, m.OrderDate)) AS MontlySalesData
PIVOT( SUM([Sales])
FOR Month IN ([January],[February],[March],[April],[May],
[June],[July],[August],[September],[October],[November],
[December])) AS PivotData
GO
-- DROP TABLE #MonthlyStock
SELECT Product
,January as JanuaryStock
,February as FebruaryStock
,March as MarchStock
,April as AprilStock
,May as MayStock
,June as JuneStock
,July as JulyStock
,August as AugustStock
,September as SeptemberStock
,October as OctoberStock
,November as NovemberStock
,December as DecemberStock
INTO #MonthlyStock
FROM (SELECT m.ProductId [Product],
DATENAME(MONTH, m.StockDate) [Month],
SUM(ISNULL(M.Quantity, 0)) [Stock]
FROM SampleStock m
GROUP BY m.ProductId,
DATENAME(MONTH, m.StockDate)) AS MontlyStock
PIVOT( SUM([Stock])
FOR Month IN ([January],[February],[March],[April],[May],
[June],[July],[August],[September],[October],[November],
[December])) AS PivotData
GO
SELECT ISNULL(sl.Product,st.Product) as Product
,JanuarySales,JanuaryStock
,FebruarySales,FebruaryStock
,MarchSales,MarchStock
,AprilSales,AprilStock
,MaySales,MayStock
,JuneSales,JuneStock
,JulySales,JulyStock
,AugustSales,AugustStock
,SeptemberSales,SeptemberStock
,OctoberSales,OctoberStock
,NovemberSales,NovemberStock
,DecemberSales,DecemberStock
FROM #MonthlySales sl
FULL JOIN #MonthlyStock st ON sl.Product = st.Product