osupratt
Posting Yak Master
238 Posts |
Posted - 2008-03-21 : 14:38:15
|
I have tried to get the rownumber for my Group which is labeled 'Customer'. I sum all the 'id.SOExtChargeAmount' on the report side. I need this so I can limit the grouping to the Top 20 customers for my other Group labeled 'Region'.I need this done on the report side of things in the layout tab. Can anyone help. Nothing I've tried from anyone has helped and I am at a standstill. If I need to sum things on the query side then I will, but do not know how to do this. Here is my current query:SELECT CASE WHEN DATEDIFF([MONTH], ih.SOTransDate, @DateFrom) = 11 THEN id.SOExtChargeAmount ELSE 0 END AS MonthLessEleven,CASE WHEN DATEDIFF([MONTH], ih.SOTransDate, @DateFrom) = 10 THEN id.SOExtChargeAmount ELSE 0 END AS MonthLessTen, CASE WHEN DATEDIFF([MONTH], ih.SOTransDate, @DateFrom) = 9 THEN id.SOExtChargeAmount ELSE 0 END AS MonthLessNine, CASE WHEN DATEDIFF([MONTH], ih.SOTransDate, @DateFrom) = 8 THEN id.SOExtChargeAmount ELSE 0 END AS MonthLessEight, CASE WHEN DATEDIFF([MONTH], ih.SOTransDate, @DateFrom) = 7 THEN id.SOExtChargeAmount ELSE 0 END AS MonthLessSeven, CASE WHEN DATEDIFF([MONTH], ih.SOTransDate, @DateFrom) = 6 THEN id.SOExtChargeAmount ELSE 0 END AS MonthLessSix, CASE WHEN DATEDIFF([MONTH], ih.SOTransDate, @DateFrom) = 5 THEN id.SOExtChargeAmount ELSE 0 END AS MonthLessFive, CASE WHEN DATEDIFF([MONTH], ih.SOTransDate, @DateFrom) = 4 THEN id.SOExtChargeAmount ELSE 0 END AS MonthLessFour, CASE WHEN DATEDIFF([MONTH], ih.SOTransDate, @DateFrom) = 3 THEN id.SOExtChargeAmount ELSE 0 END AS MonthLessThree, CASE WHEN DATEDIFF([MONTH], ih.SOTransDate, @DateFrom) = 2 THEN id.SOExtChargeAmount ELSE 0 END AS MonthLessTwo, CASE WHEN DATEDIFF([MONTH], ih.SOTransDate, @DateFrom) = 1 THEN id.SOExtChargeAmount ELSE 0 END AS MonthLessOne, CASE WHEN DATEDIFF([MONTH], ih.SOTransDate, @DateFrom) = 0 THEN id.SOExtChargeAmount ELSE 0 END AS CurrentMonth, CASE WHEN DATEDIFF([YEAR], ih.SOTransDate, @DateFrom) = 0 THEN id.SOExtChargeAmount ELSE 0 END AS CurrentYearTotal, CASE WHEN DATEDIFF([YEAR], ih.SOTransDate, @DateFrom) = 1 THEN id.SOExtChargeAmount ELSE 0 END AS LastYearTotal, CASE WHEN DATEADD([year], - 1, @DateFrom) > ih.SOTransDate AND DATEDIFF([YEAR], ih.SOTransDate, @DateFrom) = 1 THEN id.SOExtChargeAmount ELSE 0 END AS LastYearYTD, case when substring(a.Account,5,3)='900' then 'ALE' when substring(a.Account,5,3)='902' then 'ATO'when substring(a.Account,5,3)='904' then 'BOW'when substring(a.Account,5,3)='906' then 'BRY'when substring(a.Account,5,3)='908' then 'BPT'when substring(a.Account,5,3)='910' then 'BYD'when substring(a.Account,5,3)='912' then 'BUF'when substring(a.Account,5,3)='914' then 'CLE'when substring(a.Account,5,3)='916' then 'GRN'when substring(a.Account,5,3)='920' then 'DXN'when substring(a.Account,5,3)='924' then 'CTH'when substring(a.Account,5,3)='926' then 'ELC'when substring(a.Account,5,3)='928' then 'FTL'when substring(a.Account,5,3)='930' then 'FTW'when substring(a.Account,5,3)='932' then 'I35'when substring(a.Account,5,3) IN ('936','000') then 'GAI'when substring(a.Account,5,3)='939' then 'STW'when substring(a.Account,5,3)='940' then 'GRE'when substring(a.Account,5,3)='942' then 'HEN'when substring(a.Account,5,3)='944' then 'FTS'when substring(a.Account,5,3)='948' then 'JAC'when substring(a.Account,5,3)='952' then 'JEN'when substring(a.Account,5,3)='956' then 'KIL'when substring(a.Account,5,3)='957' then 'MCA'when substring(a.Account,5,3)='958' then 'MIN'when substring(a.Account,5,3)='960' then 'NOC'when substring(a.Account,5,3)='962' then 'ODE'when substring(a.Account,5,3)='964' then 'BTP'when substring(a.Account,5,3)='966' then 'RA'when substring(a.Account,5,3)='968' then 'RIF'when substring(a.Account,5,3)='970' then 'SWD'when substring(a.Account,5,3)='971' then '3PS'when substring(a.Account,5,3)='972' then 'ROC'when substring(a.Account,5,3)='976' then 'SJO'when substring(a.Account,5,3)='978' then 'SMB'when substring(a.Account,5,3)='980' then 'STO'when substring(a.Account,5,3)='982' then 'TOL'when substring(a.Account,5,3)='984' then 'VEL'when substring(a.Account,5,3)='985' then 'CFP'when substring(a.Account,5,3)='986' then 'CLM'when substring(a.Account,5,3)='988' then 'WHI'when substring(a.Account,5,3)='992' then 'WRA'when substring(a.Account,5,3)='995' then 'ADM' ELSE 'Unknown'END AS Location, case when substring(a.Account,5,3) IN ('000','900','904','908','910','914','920','930','932','936','939','948','960','964','966','970','971','976','978','980','982','985','986','988','995') then 'North Region'when substring(a.Account,5,3) IN ('902','957','984') then 'Woodford Region'when substring(a.Account,5,3) IN ('906','926') then 'South Region'when substring(a.Account,5,3) IN ('912','924','942','952','956','958') then 'East Region'when substring(a.Account,5,3) IN ('916','944') then 'Fayetteville Region'when substring(a.Account,5,3) IN ('928','940','968','972','992') then 'Rockies Region'when substring(a.Account,5,3) = '962' then 'West Region' ELSE ' 'END AS Region, ih.SOTransDate, ih.InvoiceNumber, cm.CustomerName, id.DetailSeqNumber, id.LineType, a.Account, id.SOExtChargeAmountFROM dbo.MAS_BSC_AR1_CustomerMaster cm, dbo.MAS_BSC_ARN_InvHistoryHeader ih, dbo.MAS_BSC_ARO_InvHistoryDetail id, dbo.MAS_BSC_GL_Account aWHERE cm.CustomerNumber = ih.CustomerNumber AND ih.InvoiceNumber = id.InvoiceNumber AND id.SOGLSalesAcct = a.AccountKey AND year(ih.SOTransDate) >= year(dateadd(year,-1, @DateFrom)) |
|