none
SQL-Order by clause not working

    Question

  • Hi Experts ,

    I am not able to insert Data from One Table to another using Order By Clause ,Below is the workAround I tried .

    CREATE TABLE TEMP1(ID INT ,DATES  DATE)

    INSERT INTO TEMP1
    SELECT 1,'2011-03-07' UNION ALL
    SELECT 2,'2010-03-06' UNION ALL
    SELECT 3,'2013-03-01' UNION ALL
    SELECT 4,'2009-03-21'

    SELECT * FROM TEMP1

    /*BELOW CODE DOES NOT GIVE THE REQUIRED OUTPUT I.E I DO NOT GET THE OUTPUT OF TEMP2 TABLE ORDER BY DATES*/

    SELECT * INTO TEMP2 FROM TEMP1 ORDER BY DATES
    SELECT * FROM TEMP2

    /*SECOND APPROACH ALSO DOES NOT WORK FOR SAME SCENARIO*/

    CREATE TABLE TEMP3 (ID INT,DATES DATE)
    INSERT INTO TEMP3
    SELECT ID,DATES FROM TEMP1 ORDER BY DATES

    SELECT * FROM TEMP3

    /*HOW DO I INSERT DATA FROM ONE TABLE TO OTHER WITH  ORDER BY ??*/

    Wednesday, March 06, 2013 1:11 PM

All replies