Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

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

1 Solution

Accepted Solutions
Not applicable
Author

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.

View solution in original post

4 Replies
Not applicable
Author

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.

CELAMBARASAN
Partner - Champion
Partner - Champion

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

jagan
Luminary Alumni
Luminary Alumni

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.

Not applicable
Author

Thanks everyone, the semicolon was indeed the problem.