Advertisement
Guest User

Untitled

a guest
Dec 24th, 2013
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. ORDER BY
  2. CASE WHEN @OrderBy = 0
  3. THEN table.id END ASC,
  4. CASE WHEN @Orderby = 2
  5. THEN table.id END ASC,
  6.  
  7. CASE WHEN @OrderBy = 4
  8. THEN (100-((table.price/table.oldprice)*100) as discount END ASC
  9.  
  10. SELECT * from [table]
  11. ORDER BY
  12. CASE @OrderBy
  13. WHEN 0
  14. THEN [table].id -- ASC
  15. WHEN 2
  16. THEN [table].id * -1 -- DESC
  17. ---I want to do something like below as I don't have discount column in table
  18. WHEN 4
  19. THEN (100-([table].price/[table].oldprice)*100)
  20. END
  21.  
  22. SELECT *, (100-(table.price/table.oldprice))*100 as discount
  23. FROM table
  24.  
  25. ORDER BY
  26. CASE WHEN @OrderBy = 0
  27. THEN table.id END ASC,
  28. CASE when @orderby=2
  29. THEN table.id END ASC,
  30. CASE WHEN @OrderBy = 4
  31. THEN discount END ASC
  32.  
  33. select * from TableName where someCondition >100
  34. order by
  35. case when @OrderBy = 'AirlineService'
  36. then AirlineService END desc,
  37. case when @OrderBy = 'SomeMore'
  38. then MyOtherColumn end
  39. GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement