Note that there are some explanatory texts on larger screens.

plurals
  1. POLog Parser ORDER BY CASE statement
    primarykey
    data
    text
    <p>Quite a trivial problem here that I can't seem to resolve. I am using LogParser to analyse some telephone system CSV log files. I am trying to produce a graph of all the incoming calls between two dates, grouped by day of the week. I have achieved this, but I am struggling to have the graph display the columns in the correct order, starting with Monday. My SQL query that I pass to LogParser is as follows:</p> <pre><code>SELECT to_string(to_timestamp(c1, 'yyyy/MM/dd HH:mm'), 'dddd') as Day, count(*) as Calls INTO graph.gif FROM C:\logs\*.txt WHERE c5 = 'I' AND to_timestamp(c1, 'yyyy/MM/dd HH:mm') BETWEEN timestamp('10/05/2012', 'dd/MM/yyyy') AND timestamp('24/05/2012', 'dd/MM/yyyy') GROUP BY Day </code></pre> <p>It actually outputs in the correct order without any ORDER BY statement at all, but I think that the first column is always the day that the date range starts on, whereas I would like it to always be Monday (for easy comparison of graphs). What happens currently is it converts the timestamp from my log file into a string representation of the day of the week (for the purpose of output) and as far as I am aware there is no built in logic that 'Monday' is less than 'Tuesday' and so on. My instinct was to use a CASE statement in an ORDER BY, but LogParser won't accept this.</p> <p>This is my entire LogParser command just in case it's relevant,</p> <pre><code>C:\Program Files (x86)\Log Parser 2.2\Logparser.exe" -i:CSV "SELECT to_string(to_timestamp(c1, 'yyyy/MM/dd HH:mm'), 'dddd') as Day, count(*) as Calls INTO graph.gif FROM C:\logs\*.txt WHERE c5 = 'I' AND to_timestamp(c1, 'yyyy/MM/dd HH:mm') BETWEEN timestamp('10/05/2012', 'dd/MM/yyyy') AND timestamp('24/05/2012', 'dd/MM/yyyy') GROUP BY Day" -chartType:Column3D -chartTitle:"Incoming Calls" -values:ON -config:MyConfig.js -o:CHART -headerRow OFF -iHeaderFile C:\logs\header\header.txt </code></pre> <p>Simply all I would like is for my results order to always start on Monday, regardless of the date range. Any ideas?</p> <p>EDIT - This is the query with the CASE statement included in the ORDER BY.</p> <pre><code>SELECT to_string(to_timestamp(c1, 'yyyy/MM/dd HH:mm'), 'dddd') as Day, count(*) as Calls INTO graph.gif FROM C:\logs\*.txt WHERE c5 = 'I' AND to_timestamp(c1, 'yyyy/MM/dd HH:mm') BETWEEN timestamp('10/05/2012', 'dd/MM/yyyy') AND timestamp('24/05/2012', 'dd/MM/yyyy') GROUP BY Day ORDER BY (CASE WHEN Day = 'Monday' THEN 1 WHEN Day = 'Tuesday' THEN 2 WHEN Day = 'Wednesday' THEN 3 WHEN Day = 'Thursday' THEN 4 WHEN Day = 'Friday' THEN 5 WHEN Day = 'Saturday' THEN 6 WHEN Day = 'Sunday' THEN 7 END) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload