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 |
|
Lady Gragor
Starting Member
2 Posts |
Posted - 2009-08-10 : 02:47:45
|
| Hi,Could someone please tell me how to avoid duplicate amounts in the subtotal field of the following SQL statement. I would like it to display the subtotal only once for the last entry for each CAT with the same value and otherwise leave the subtotal field blank.SELECT qry_Claim.Field1, qry_Claim.Field2, qry_Claim.WBS, qry_Claim.CAT, qry_Claim.[CAT Description], qry_Claim.Date, qry_Claim.Vendor, qry_Claim.Description, qry_Claim.Units, qry_Claim.Amount, qry_Totals.SumOfField12 AS SubtotalFROM qry_Claim LEFT JOIN qry_Totals ON qry_Claim.CAT = qry_Totals.Field6;Thanks in advance |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2009-08-10 : 02:54:42
|
| Can you post some sample data and expected result?Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-08-10 : 02:55:07
|
| do u have any date column in ur table qry_Totals ?if yes then use row_number funciton |
 |
|
|
Lady Gragor
Starting Member
2 Posts |
Posted - 2009-08-10 : 07:21:34
|
| Sample data of claim queryField1 Field2 WBS CAT CAT Description Date Vendor Units1234 2345 1-01-01 007 a description 24/06/09 ABCD 11234 2345 1-01-01 007 a description 30/06/09 ABCD 3Field12$128.00$700.00Every line of the file has a CAT number. The number of lines containing the same CAT number is unknown.Sample data of totals queryField1 Field3 Field6 SumOfField121234 1-01-01 007 $828.001234 1-01-01 024 $700.521234 1-01-01 051 $254.821234 1-01-01 061 $112.56I would like it to appear as follows(summarised here)Field1 Field3 Field6 Field 12 SumOfField121234 1-01-01 007 $128.001234 1-01-01 007 $700.00 $828.001234 1-01-01 061 $112.561234 1-01-01 061 $112.56 1234 1-01-01 061 $256.90 $482.02I hope this makes sense |
 |
|
|
|
|
|