mahmed1
Well-known Member
- Joined
- Mar 28, 2009
- Messages
- 2,302
- Office Version
- 365
- 2016
- Platform
- Windows
Hiya
I've got this SQL statement in excel to pull back data from access into my excel sheet
This works fine but takes around 10-12 minutes to run each time and was hoping i can speed this up...I believe it may be the join or the In statement that makes it take long
Hopefully you can help me speed it up
I've got this SQL statement in excel to pull back data from access into my excel sheet
This works fine but takes around 10-12 minutes to run each time and was hoping i can speed this up...I believe it may be the join or the In statement that makes it take long
Hopefully you can help me speed it up
VBA Code:
SQLQuery = "SELECT t.Date AS [Date], t.Department AS Department, SUM(t.Requested) AS Requested, SUM(t.Connected) AS Connected, SUM(t.Requested) - SUM(t.Connected) AS Abandoned, MAX(ROUND(IIF(Requested > 0, Connected/Requested, 0), 2)) AS PWA, SUM(t.THT)/SUM(IIF(t.Connected>0,t.Connected,9.999999E+306)) AS AHT, SUM(t.TSA)/SUM(IIF(t.Connected>0,t.Connected,9.999999E+306)) AS ASA" & _
" FROM (SELECT roll.DATE AS [Date], lkup.Department As Department, IIF(SUM(roll.[REQUESTED CHATS])>0,SUM(roll.[REQUESTED CHATS]),0) AS Requested, IIF(SUM(roll.[CONNECTED CHATS])>0, SUM(roll.[CONNECTED CHATS]),0) AS Connected, SUM(roll.THT) AS THT, SUM(roll.TSA) AS TSA" & _
" FROM tbl_WebChatRolling AS roll INNER JOIN lookup_WebChat AS lkup ON lkup.Skill = roll.SKILL" & _
" WHERE roll.DATE Is Not Null And lkup.Department In " & Zx & " And ([Date] Between #" & fromDate & "# And #" & toDate & "#) And ((CStr(Format(roll.HOUR, 'hh:mm')) IN ('08:00', '09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '19:00', '20:00')) AND (CStr(Format(roll.Date, 'ddd')) IN ('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat')))" & _
" GROUP BY roll.DATE, lkup.Department" & _
" ORDER BY lkup.Department, roll.DATE" & _
" UNION ALL" & _
" SELECT roll.DATE AS [Date], lkup.Department AS Department, IIF(SUM(roll.[REQUESTED CHATS])>0,SUM(roll.[REQUESTED CHATS]),0) AS Requested, IIF(SUM(roll.[CONNECTED CHATS])>0, SUM(roll.[CONNECTED CHATS]),0) AS Connected, SUM(roll.THT) AS THT, SUM(roll.TSA) AS TSA" & _
" FROM tbl_WebChatRolling AS roll INNER JOIN lookup_WebChat_Night AS lkup ON lkup.Skill = roll.SKILL" & _
" WHERE roll.DATE Is Not Null And lkup.Department In " & Zx & " And ([Date] Between #" & fromDate & "# And #" & toDate & "#) And ((CStr(Format(roll.HOUR, 'hh:mm')) IN ('00:00', '01:00', '02:00', '03:00', '04:00', '05:00', '06:00', '07:00', '21:00', '22:00', '23:00')) OR (CStr(Format(roll.Date, 'ddd')) IN ('Sun')))" & _
" GROUP BY roll.DATE, lkup.Department) AS t" & _
" GROUP BY t.Date, t.Department" & _
" ORDER BY t.Date, t.Department"