I have a robust query that returns a dataset and the data is good, however some of the records contain the exact same data with the exception of the 'Price' field. I want to combine the records that are identical and SUM the values in the 'Price' field. My query and example return dataset is below.Query:--------select distinct'On-Demand' as 'Business Line',o.OrderID as 'Order #',isnull(d.DisplayCode,'UNK') as Hub,isnull(rz.RouteID,'UNK') as 'Default Route','On-Demand' as 'Assigned Route',o.DestAddress,o.DestZip,C.LocalName,C.CustID,DATENAME(dw,o.OrderDate) as 'DoW',DATENAME(ww,o.OrderDate) as 'Week',o.Pieces,OI.Price AS '$',ct.CustType,'Everything Else' as 'Code Section'from tblOrder oleft outer join tblZones z on o.Destzip = z.zipleft outer join tblZonesRouteZones rz on z.ZoneID = rz.ZoneID and rz.RouteLookupID = 1left outer join tblDepots d on z.DepotID = d.DepotIDjoin tblCustomer c on o.CustID = c.CustIDjoin tblCustomerTypes ct on c.CustType = ct.CustTypeIDINNER JOIN tblOrderItems OI ON OI.OrderID = CAST(O.OrderID AS VARCHAR(10))where o.OrderDate >= @StartDate and o.OrderDate <= @EndDate and o.Pieces >= '1' and o.CustID in (750,3103,2835,718,3580,3578,3579,3430,3388,3577,2473,3653,3655,3654,13,1661,3603,3676,3662,3665,3586,3597,1536,3593,979,3554,551,3247,1715,1388,559,3650,3652,3651,3613,2732,3619,3165,3295,2980,3301,1179,33,3379,633,3673,3362,3478,9997,3218,3336,3342,2704,3484,3510,3614,2868,3644,3636,3642,3516,3424,3401,3646,3530,3435,3506,3539,3542,3536,3520,3535,3591,3524,3596,3538,3504,3513,3635,3502,3525,3511,3518,3515,3519,3574,3517,3531,3638,3640,3643,3571,3523,3526,3505,3595,3537,3639,3503,3572,3521,3512,3634,3564,3570,3514,3499,3522,3529,3507,3540,3645,3637,3532,3641) and o.DestZip like '[3][2-9]%' -- First FL zip code is 32003 and c.LocalName <> 'KMart Pharmacy' and o.DestAddress <> '5002 W Nassau St' and OI.Price >= '.01'Order by "Address","LocalName", "Default Route"Dataset Returned:---------------------[img]http://www.sonictl.com/images/example.jpg[/img]
↧