Problem:
Some fields in my table have the wrong date format, they are formatted using the .ToString () method in C #, but I made a typo and entered it like this: MM / dd / yyyy hh: mm / ss tt
Now, if you look carefully, you will see MM / dd / yyyy hh: mm ----> ' / ' <--- ss
which should be : '
I was preceded to fix it in my C # code (this means that some of the values are formatted: MM / dd / yyyy hh: mm: ss tt )
The problem is that I'm trying to select values from a table in Date order (which I cannot just sort by 'Datefieldnamehere'), because some of the fields are in the wrong format with the character '/'
What I tried:
Now, I realized that time is always in the same place (and that is important to me), I could just take a substring of numbers for the time and order them; first for AM , then for PM
I could order by MID ([ColumnName], 11,2), MID ([ColumnName], 14,2), MID ([ColumnName], 16,2), because each date, regardless of the separator, is always in M format / dd / yyyy hh / mm / ss tt
So I tried:
(
SELECT SN, StatusCode, Time, Mid(Time,14,2) + ':'+ Mid(Time,17,2) AS TTI
FROM OrderStatus
WHERE StatusCode = 'Finished' and Left(Time,10) = '4/20/2012'
AND Time LIKE '*AM'
ORDER BY Val(Mid([Time],11,2)) DESC
)
UNION ALL (
SELECT SN, StatusCode, Time, Mid(Time,14,2) + ':'+ Mid(Time,17,2) AS TTI
FROM OrderStatus
WHERE StatusCode = 'Finished' and Left(Time,10) = '4/20/2012'
AND Time LIKE '*PM'
ORDER BY Val(Mid([Time],11,2)) DESC
);
Just to find out if it will order it by the hour, but it does not give me this:

As you can see, it goes (in the hour field) 01, then 02, and then returns to 01 ...?
, . , , ,
Edit:
, , ; , , , , //, , - :
Order By Val ( (ColumnName, StartPos, EndPos))
: .