Help With MS Query Sum Distinct
People forget the SQL's are long strings try this
SelectSQL = _
"SELECT DISTINCT v_inputfiles.sName AS 'Client Name'," & _
"ciSE.ciSEqty," & _
"ciSE.ciSEvalue," & _
"ciSE.ciSECharge," & _
"ciSE.ciSEInRefSource," & _
"ciSE.ciSEInRefData"
FromSQL = _
"FROM chronosv2.dbo.ciSE ciSE," & _
"chronosv2.dbo.v_inputfiles v_inputfiles"
WhereSQL = _
"WHERE ciSE.ciSEclient = v_inputfiles.sID AND " & _
"((ciSE.ciSEbillingmonth='2008-10'))"
GroupSQL = _
"GROUP BY v_inputfiles.sName, " & _
"ciSE.ciSEID, " & _
"ciSE.ciSEqty, " & _
"ciSE.ciSEvalue, " & _
"ciSE.ciSECharge, " & _
"ciSE.ciSEInRefSource," & _
"ciSE.ciSEInRefData"
HavingSQL = _
"HAVING (ciSE.ciSEInRefSource='TM') AND (ciSE.ciSEInRefData='ELIST')"
Sql = SelectSQL & FromSQL & WhereSQL & HavingSQL
"Lexster" wrote:
Hi everyone.
I hope someone can help me out with a SQL formula I am using with MS
Query in Excel.
This is what I have right now:
SELECT DISTINCT v_inputfiles.sName AS 'Client Name', ciSE.ciSEID AS
'Transaction ID', ciSE.ciSEqty, ciSE.ciSEvalue, ciSE.ciSECharge,
ciSE.ciSEInRefSource, ciSE.ciSEInRefData
FROM chronosv2.dbo.ciSE ciSE, chronosv2.dbo.v_inputfiles v_inputfiles
WHERE ciSE.ciSEclient = v_inputfiles.sID AND
((ciSE.ciSEbillingmonth='2008-10'))
GROUP BY v_inputfiles.sName, ciSE.ciSEID, ciSE.ciSEqty,
ciSE.ciSEvalue, ciSE.ciSECharge, ciSE.ciSEInRefSource,
ciSE.ciSEInRefData
HAVING (ciSE.ciSEInRefSource='TM') AND (ciSE.ciSEInRefData='ELIST')
What I need help with is adjusting this SQL command so that I get rid
ciSE.ciSEID AS 'Transaction ID' but still maintain the same results. I
used the ciSE.ciSEID field because it was used to filter out
duplicates. However when I take this field out and use the Distinct,
my sum includes all the duplicates.
My goal is to have the sum of ciSE.ciSEqty, ciSE.ciSEvalue,
ciSE.ciSECharge grouped by v_inputfiles.sName AS 'Client Name' - which
will bring over fewer rows.
I would greatly appreciate any suggestions and help on this.
Thank you in advance.
|