I have made sample for you check this hope this will help you.
CREATE TABLE [dbo].[TableA](
[ID] [INT] NOT NULL,
[TotalProductSum] [INT] NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[TableB](
[ID] [INT] NOT NULL,
[Products] [varchar](30) NOT NULL,
[Value] [INT] NOT NULL
) ON [PRIMARY]
INSERT INTO [dbo].[TableA]
([ID],[TotalProductSum])
VALUES (11,1000)
INSERT INTO [TestTB].[dbo].[TableB] ([ID],[Products],[Value])
VALUES (11 ,'10' ,80)
INSERT INTO [TestTB].[dbo].[TableB] ([ID],[Products],[Value])
VALUES (11 ,'20' ,30)
INSERT INTO [TestTB].[dbo].[TableB] ([ID],[Products],[Value])
VALUES (11 ,'30' ,45)
INSERT INTO [TestTB].[dbo].[TableB] ([ID],[Products],[Value])
VALUES (11 ,'40' ,56)
select * from TableA
select * from TableB
SELECT A.ID,A.Products,A.Value,B.TotalproductSum- SUM(a.value) OVER (ORDER BY A.Products) NewTotalProductSum
from
TableB as A INNER JOIN TableA AS B
ON A.ID=B.ID
ORDER BY a.id;
The Result will be like this
Table A
11 1000
TableB
11 10 80
11 20 30
11 30 45
11 40 56
The result Query will be like this (
NewTotalProductSum [Value - [Previous]TotalProductSum]
)
11 10 80 920
11 20 30 890
11 30 45 845
11 40 56 789