Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
tyekhan786
Starting Member
9 Posts |
Posted - 2014-07-17 : 08:24:36
|
need to the below information to have the hours down the row & have MULTI_SUB_FLAG across the top with only displaying the con figures under it.SELECT DATEPART(hour, History.CallDateTime) AS hours, OverallTable.MULTI_SUB_FLAG, SUM(CASE LastCR2 WHEN 'EE002' THEN SuccessValue * 1 WHEN 'EE003' THEN SuccessValue * 1 WHEN 'EE004' THEN SuccessValue * 1 ELSE SuccessValue END) AS TotalSalesINTO totalsalestFROM OverallTable INNER JOIN History ON OverallTable.DID = History.DID INNER JOIN EECR2SuccessValues ON History.CR2 = EECR2SuccessValues.CR2WHERE (OverallTable.paygMigration = N'June 14')GROUP BY OverallTable.MULTI_SUB_FLAG, DATEPART(hour, History.CallDateTime)goSELECT DATEPART(hour, History.CallDateTime) AS hours, OverallTable.MULTI_SUB_FLAG, COUNT(CR2.Contact) AS TotalDmcsINTO totaldmcstFROM OverallTable INNER JOIN History ON OverallTable.DID = History.DID INNER JOIN CR2 ON History.CR2 = CR2.CR2WHERE (OverallTable.paygMigration = N'June 14') AND (CR2.Contact = 1)GROUP BY OverallTable.MULTI_SUB_FLAG, DATEPART(hour, History.CallDateTime)goSELECT totaldmcst.hours, totaldmcst.MULTI_SUB_FLAG, totalsalest.TotalSales, totaldmcst.TotalDmcs, CONVERT(varchar(5), CONVERT(numeric(4, 1), (SUM(totalsalest.TotalSales) / 1.0) / (SUM(totaldmcst.TotalDmcs) / 1.0) * 100)) AS ConFROM totaldmcst INNER JOIN totalsalest ON totaldmcst.hours = totalsalest.hours AND totaldmcst.MULTI_SUB_FLAG = totalsalest.MULTI_SUB_FLAGGROUP BY totaldmcst.hours, totaldmcst.MULTI_SUB_FLAG, totalsalest.TotalSales, totaldmcst.TotalDmcs--------------------this is the output now 9 N 41.00 1070 3.89 Y 2.00 98 2.010 N 352.00 5611 6.310 Y 32.00 413 7.711 N 554.00 9220 6.011 Y 65.00 672 9.712 N 563.00 10069 5.612 Y 68.00 915 7.413 N 450.00 7838 5.713 Y 60.00 772 7.814 N 530.00 10385 5.114 Y 68.00 807 8.415 N 281.00 5402 5.215 Y 26.00 460 5.716 N 439.00 7835 5.616 Y 31.00 702 4.417 N 294.00 5476 5.417 Y 26.00 543 4.818 N 423.00 8011 5.318 Y 38.00 486 7.819 N 380.00 6647 5.719 Y 26.00 387 6.720 N 5.00 10 50.0--------------------But want this output, N Y9 3.8 210 6.3 7.711 6 9.712 5.6 7.413 5.7 7.814 5.1 8.415 5.2 5.716 5.6 4.417 5.4 4.818 5.3 7.819 5.7 6.720 50 |
|
stepson
Aged Yak Warrior
545 Posts |
Posted - 2014-07-17 : 08:50:55
|
[code];with aCTEAS (SELECT 9 AS [hours],'N' AS MULTI_SUB_FLAG,41.00 AS TotalSales,1070 AS TotalDmcs,3.8 AS Con UNION ALL SELECT 9,'Y',2.00,98,2.0 UNION ALL SELECT 10,'N',352.00,5611,6.3 UNION ALL SELECT 10,'Y',32.00,413,7.7 UNION ALL SELECT 19,'N',380.00,6647,5.7 UNION ALL SELECT 19,'Y',26.00,387,6.7 UNION ALL SELECT 20,'N',5.00,10,50.0)SELECT [hours] ,SUM(CASE WHEN MULTI_SUB_FLAG ='N' THEN Con ELSE 0 END) as [N] ,SUM(CASE WHEN MULTI_SUB_FLAG ='Y' THEN Con ELSE 0 END) as [Y] FROM aCTE GROUP BY [hours][/code]sabinWeb MCP |
|
|
|
|
|
|
|