Duplicate records
- From: P.S.Bell <pat@xxxxxxxxxxxxx>
- Date: Fri, 31 Mar 2006 17:12:31 +0100
I had a query with a sum on a detail field. This was fine until
I found I needed to apply proper rounding prior to summing. It
now lists a row for each detail record. I have guessed/tried to
add the case to the group by instead of the field but I am told
I cannot have a subclause.
Here is the query, can anyone help?
SELECT TOP 100 PERCENT Jobs.JobNo, Jobs.FinalReport,
Jobs.LicInvoiceNo, LicencesHeld.LicName, SUM(ItemActions.CHNet)
AS TotalNet, Jobs.AppliedFeeRate,
Areas.AreaManager,
LicenceTypes.LicenceType,CASE ABS(cast
(ItemActions.VatTotalSales*100 as int)) % 2
WHEN 1 THEN
SUM(ROUND(ItemActions.VatTotalSales+0.001,2))
ELSE SUM(ROUND
(ItemActions.VatTotalSales-0.001,2))
END AS TotalVAT
FROM ItemActions INNER JOIN
Items ON ItemActions.ItemID = Items.ItemID
INNER JOIN
Jobs ON Items.JobNo = Jobs.JobNo INNER
JOIN
LicencesHeld ON Jobs.LicID =
LicencesHeld.LicID INNER JOIN
LicenceTypes ON LicencesHeld.LicTypeID =
LicenceTypes.LicenceTypeID INNER JOIN
Areas ON LicencesHeld.AreaCode =
Areas.AreaID
GROUP BY Jobs.JobNo, Jobs.FinalReport, Jobs.LicInvoiceNo,
LicencesHeld.LicName, Jobs.AppliedFeeRate, Areas.AreaManager,
LicenceTypes.LicenceType,
ItemActions.VatTotalSales
HAVING (NOT (Jobs.LicInvoiceNo IS NULL)) AND
(LicenceTypes.LicenceType LIKE '%%') AND (Jobs.FinalReport
BETWEEN CONVERT(DATETIME,
'2006-01-01 00:00:00', 102) AND
CONVERT(DATETIME, '2999-01-01 00:00:00', 102))
ORDER BY Jobs.LicInvoiceNo
Pat Bell
.
- Follow-Ups:
- Re: Duplicate records
- From: Ralf Jansen
- Re: Duplicate records
- Prev by Date: Re: Dynamically Adding an Index to a query
- Next by Date: Re: Dynamically Adding an Index to a query
- Previous by thread: Dynamically Adding an Index to a query
- Next by thread: Re: Duplicate records
- Index(es):
Relevant Pages
|