MS SQL 2012 ORDER BY Not Working
Posted on 2013-11-18
I'm clearly doing something wrong here, but have no idea what it is. I have the following code, which should copy all the columns into a new table (RemAds), converting a date and then ordering the new table by that date:
SET DATEFORMAT dmy
SELECT *, convert(smalldatetime,Rem_Date, 103) as Rem_Date_Date
FROM [dbo].['1213 Remittance Advices$']
WHERE ISDATE(Rem_Date) = 1
) as Rem_Date_Date
ORDER BY Rem_Date_Date ASC;
Everything works except the ORDER BY bit. If I export the file into Excel, the dates are coming out as yyyy-mm-dd hh:mm:ss (I'm guessing at the last bit as they're all zero).
What am I doing wrong here?
I'm awarding 500 points for a quick and working solution as this is the last bit I need to get the whole damn thing working, even though it's not pretty, and I need to get some numbers ready for a meeting.