Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sorting by two columns

Status
Not open for further replies.

Jeremy21b

Technical User
Jul 7, 2002
127
CA
I have a table with 2 different price columns. One is a special price for a different currency. Sometimes that column is blank. Is there a way to properly sort the query on both columns together? I don't mean order by price1, price2. I want to sort them as if they were the same column. Also is there a way to sort this with the one column multiplied by a conversion rate? In a perfect world my syntax would be: order by price1 and (price2 * conversionrate)
 
I think the answer is yes, but I'm not sure exactly what you want. Maybe this is what you want?
Code:
   ORDER BY Case When Price2>0 THEN Price2*ConversionRate ELSE Price1 END
If that's not it, then modify the case statement for whatever it is that you want.
-Karl

[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
Thank you Karl. I had no idea that you could use Cases in an order by. That was exactly what I needed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top