Greetings,
I have a query:
Which gives me the following:
ColumnLabel ColumnValue ColumnPK Series
Jan 73 01/2014 Current period
Feb 89 02/2014 Current period
Mar 73 03/2014 Current period
Apr 58 04/2014 Current period
May 15 05/2014 Current period
Jun 39 06/2013 Current period
Jul 40 07/2013 Current period
Aug 80 08/2013 Current period
Sep 86 09/2013 Current period
Oct 77 10/2013 Current period
Nov 50 11/2013 Current period
Dec 60 12/2013 Current period
I need this to sort by the third column so that the data returned is oldest to newest. I tried to do an ORDER BY on RIGHT(ColumnPK,4) as a start but that did't work. I also tried to do an ORDER BY ColumnLabel to test. That didn't work either.
Can anyone help?
Thanks!
Ed
I have a query:
Code:
SELECT Sum(ColumnValue) AS SOCount, ColumnPK
INTO #TT1010
FROM
(SELECT SUBSTRING(DATENAME(mm, DT.dtime), 0, 4) AS ColumnLabel, Data.ColumnValue,
CASE WHEN datepart(mm, DT.dtime) < 10
THEN '0' + CAST(datepart(mm, DT.dtime) AS VARCHAR(1)) + '/' + CAST(datepart(yy, DT.dtime) AS VARCHAR(4))
ELSE CAST(datepart(mm, DT.dtime) AS VARCHAR(2)) + '/' + CAST(datepart(yy, DT.dtime) AS VARCHAR(4))
END AS ColumnPK, 'Current period' AS Series
FROM (
SELECT COUNT(s.SONumber) AS ColumnValue, DateClosed AS ColumnPK
FROM tblServiceOrders s
WHERE s.FKDispatchBoardKeyID = 6 AND s.Status <> 'Void' AND DateOpened Is Not Null AND TimeOpened Is Not Null AND DateClosed Is Not Null and TimeClosed Is Not Null
GROUP BY s.SONumber, DateClosed
) AS Data RIGHT OUTER JOIN dbo.tf_udfDateTimes(@CPStartDate, @CPEndDate, 1, 'day', 0) AS DT ON Data.ColumnPK = DT.dtime
) AS ForGroupBy
GROUP BY ColumnLabel, ColumnPK, Series
Which gives me the following:
ColumnLabel ColumnValue ColumnPK Series
Jan 73 01/2014 Current period
Feb 89 02/2014 Current period
Mar 73 03/2014 Current period
Apr 58 04/2014 Current period
May 15 05/2014 Current period
Jun 39 06/2013 Current period
Jul 40 07/2013 Current period
Aug 80 08/2013 Current period
Sep 86 09/2013 Current period
Oct 77 10/2013 Current period
Nov 50 11/2013 Current period
Dec 60 12/2013 Current period
I need this to sort by the third column so that the data returned is oldest to newest. I tried to do an ORDER BY on RIGHT(ColumnPK,4) as a start but that did't work. I also tried to do an ORDER BY ColumnLabel to test. That didn't work either.
Can anyone help?
Thanks!
Ed