4 Replies Latest reply: Mar 2, 2012 7:57 AM by elinestroo RSS

    How to use order by in SQL

      Hi,

       

      I want to sort data in SQL using ORDER BY, but the formula is not working for some reason...

       

      This is how i did it:

       

      Load

      //    "No_" as DocumentNo

         "Document No_"&'-'&"No_" as DocuItemNo

         , "Sell-to Customer No_"as CustomerNo

         , "Package Tracking No_" as PackageTrackingNo

         , "Promotion Name" as PromotionName

         , "Promotion ID" as PromotionID

         , "Discount Description" as DiscountDescription 

         ;

      SQL SELECT  

             "Document No_"

         , "Sell-to Customer No_"   

         , "No_"  

         , "Package Tracking No_"

         , "Promotion Name"  

         , "Promotion ID"

         , "Discount Description" 

      FROM "$(DB_DATASOURCE)".dbo."$(DB_COMPANY)$Sales Invoice Line";

      ORDER BY "Sell-to Customer No_";

       

      Can anyone tell me what i'm doing wrong?

       

      Thanks,

      Eline

        • How to use order by in SQL

          Did you try removing the semicolon after your from statement?

           

          e.g. FROM "$(DB_DATASOURCE)".dbo."$(DB_COMPANY)$Sales Invoice Line";

           

          That clears up the error for me.

          • How to use order by in SQL
            Celambarasan Adhimulam

            Hi,

                 I think semicolon is your problem which you placed the order by clause after the semicolon.

                 If you are not clear then execute the query used here in the database whether you getting results in order.

                

            SQL SELECT 

                   "Document No_"

               , "Sell-to Customer No_"  

               , "No_" 

               , "Package Tracking No_"

               , "Promotion Name" 

               , "Promotion ID"

               , "Discount Description"

            FROM "$(DB_DATASOURCE)".dbo."$(DB_COMPANY)$Sales Invoice Line"

            ORDER BY "Sell-to Customer No_";

             

             

            Celambarasan

            • How to use order by in SQL
              jagan mohan rao appala

              Hi,

               

              The semicolor may be the issue.  Try this

               

              SELECT  

                     "Document No_"

                 , "Sell-to Customer No_"   

                 , "No_"  

                 , "Package Tracking No_"

                 , "Promotion Name"  

                 , "Promotion ID"

                 , "Discount Description" 

              FROM "$(DB_DATASOURCE)".dbo."$(DB_COMPANY)$Sales Invoice Line"

              ORDER BY "Sell-to Customer No_";

               

              Still if you got the error try hardcoding the DataSource and Database name and check whether this is the issue.

               

              Hope this helps you.

               

              Regards,

              Jagan.