Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
sanjay_jadam
Yak Posting Veteran
53 Posts |
Posted - 2005-05-25 : 02:32:04
|
| Hi to all,Is anyone help me for solve my problemHow can i compare and add previous row values to the next row values.Eg:-I have a View which generate this result setMaterial Quantity month year A 100 4 2005 A 40 5 2005 A 100 6 2005 B 100 4 2005 B 120 5 2005so i need to calculate the total quantity of material A and B ....required result is Material Quantity month year A 100 4 2005 A 140 5 2005 A 240 6 2005 B 100 4 2005 B 220 5 2005Means that i want to add quantity for a previous month to the next month. But Material name must be same.How can i get this type of result Please help me ASAP.Thanks in advanceRegardsSanjay Jadam |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-05-25 : 02:56:55
|
| Select Material,(select sum(Quantity) from yourtable where Material=T.Material and Month<=T.Month) as Quantity,Month,year from yourtable TMadhivananFailing to plan is Planning to fail |
 |
|
|
sanjay_jadam
Yak Posting Veteran
53 Posts |
Posted - 2005-05-25 : 05:32:24
|
| Hi,ThanksBut i got an error Internal SQL Server error.Actully i have a table name stock and Material tableStock table having these fieldsID_Material----Transactiondate----QuantityReceived----QuantityIssued and so on I get this result Material Quantity month yearA 100 4 2005A 40 5 2005A 100 6 2005B 100 4 2005B 120 5 2005using this querySELECT M.Itemname,SUM(QuantityReceived-quantityIssued) as 'Balance',MONTH(transactionDate) AS 'StkMonth', YEAR(transactionDate) as 'StkYear'FROM stocks S INNER JOIN Material M ON S.ID_Material=M.ID_Material GROUP BY M.ITEMNAME,MONTH(transactiondate),YEAR(transactiondate)By modifying this query i need these result Material Quantity month yearA----------100---- 4--- 2005A----------140 ----5--- 2005A ---------240-----6--- 2005B--------- 100-----4----2005B--------- 220---- 5----2005so please help me |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-05-25 : 05:54:48
|
| Move the result data to temporary table and write the query based on that tableMadhivananFailing to plan is Planning to fail |
 |
|
|
sanjay_jadam
Yak Posting Veteran
53 Posts |
Posted - 2005-05-25 : 08:45:46
|
| thanks I have done it.Thanks once again |
 |
|
|
sanjay_jadam
Yak Posting Veteran
53 Posts |
Posted - 2005-05-25 : 08:57:47
|
| Can you tell me which book i preferred for a developer level knowledge in SQL Server.I need a good book on T-SQL programming in which most of the method included and good information for the stroed procedure and other SQL server topicThanksSanjay Jadam |
 |
|
|
|
|
|