Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to return group total by shortest item
Message
From
16/07/2008 17:36:58
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
How to return group total by shortest item
Miscellaneous
Thread ID:
01331819
Message ID:
01331819
Views:
57
Hi,

I keep thinking there should be an easy way to query for what I need but just can't come up with anything so here it goes.

In a typical accounting PO line-item table which stores item number and cost, I need to sum the cost by highest group item number. For example, if I have data similar to show below:


Item # Item Cost
----------------- ---------------
ABC 10.00
ABC1 20.00
ABC23 40.00
ABC456 50.00
XYZ 11.00
XYZ1 22.00
XYZ23 33.00
XYZ456 44.00
etc..

I want a group total that returns the "shortest item #" with associated sum of the costs like so:

Item # Item Cost
----------------- ---------------
ABC 120.00
XYZ 110.00

The tricky part is that the length of the shortest item # in a group is not constant. It would be very easy if it was. Any ideas? TIA.
It's "my" world. You're just living in it.
Next
Reply
Map
View

Click here to load this message in the networking platform