I have table with three columns float - float - inti have query to calculate balance for-each rowThe next code to create the table and some of data for exampleIF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TestFLoat]') AND type in (N'U'))BEGINCREATE TABLE [dbo].[TestFLoat]( [AddQuantity] [float] NOT NULL, [ExQuantity] [float] NOT NULL, [ID] [int] IDENTITY(1,1) NOT NULL) ON [PRIMARY]ENDGOSET IDENTITY_INSERT [dbo].[TestFLoat] ON GOINSERT [dbo].[TestFLoat] ([AddQuantity], [ExQuantity], [ID]) VALUES (1.53, 0, 3)GOINSERT [dbo].[TestFLoat] ([AddQuantity], [ExQuantity], [ID]) VALUES (0, 1.53, 4)GOINSERT [dbo].[TestFLoat] ([AddQuantity], [ExQuantity], [ID]) VALUES (5.13, 0, 5)GOINSERT [dbo].[TestFLoat] ([AddQuantity], [ExQuantity], [ID]) VALUES (9.25, 0, 6)GOINSERT [dbo].[TestFLoat] ([AddQuantity], [ExQuantity], [ID]) VALUES (0, 1.56, 7)GOINSERT [dbo].[TestFLoat] ([AddQuantity], [ExQuantity], [ID]) VALUES (0, 3.57, 8)GOINSERT [dbo].[TestFLoat] ([AddQuantity], [ExQuantity], [ID]) VALUES (0, 9.25, 9)GOINSERT [dbo].[TestFLoat] ([AddQuantity], [ExQuantity], [ID]) VALUES (15.08, 0, 10)GOSET IDENTITY_INSERT [dbo].[TestFLoat] OFFGO
The next code is for my query i wantSELECT AddQuantity ,ExQuantity ,SUM(AddQuantity-ExQuantity) OVER ( ORDER BY ID ROWS UNBOUNDED PRECEDING) AS CurrentQuantityFROM dbo.TestFLoat
after execute this query look at the line number 7 it must be 0 not else AddQuantity ExQuantity CurrentQuantity1- 1.53 0 1.532- 0 1.53 03- 5.13 0 5.134- 9.25 0 14.385- 0 1.56 12.826- 0 3.57 9.257- 0 9.25 -1.77635683940025E-158- 15.08 0 15.08
Mohamed Ali Salim