Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Query Output
Message
 
 
To
22/07/2003 06:44:24
General information
Forum:
Microsoft SQL Server
Category:
Other
Title:
Miscellaneous
Thread ID:
00812274
Message ID:
00812587
Views:
11
Hi Mufi,

You can use derived table to calculate running total so you can easily reference it in consequent calculations by column name.
SELECT ds3.date, dt1.OpBal, 
		ISNULL(dt1.OpBal,0) + ds3.production AS Total, ds3.sale, 
		ISNULL(dt1.OpBal,0) + ds3.production - ds3.sale	AS Closing
	FROM dailystock ds3
  JOIN ( SELECT date, (SELECT SUM(production) - SUM(sale)
			FROM dailystock ds2 
			WHERE ds2.date < ds1.date)  as OpBal
        FROM dailystock ds1 ) dt1 ON ds3.date = dt1.date
>Hi,
>
>
>How to get following output in SqlServer 2000.
>My table is bellow
>
>
>Create Table dailystock (
>Date datetime,
>Production numeric,
>Sale numeric)
>
>Required Output :
>	  A	      B		A+B	C	(A+B)-C
>Date	  Op.Bal  Production	Total	Sale	Closing
>-----------------------------------------------------------
>01-04-02  Nil	      35	35	10	 25
>02-04-02  25	      55	80		 80
>03-04-02  80	      66	146	20	 126
>04-04-02  126	      10	136		 136
>05-04-02  136	      10	146	10	 136
>06-04-02  136			136	15	 121
>
--sb--
Previous
Reply
Map
View

Click here to load this message in the networking platform