Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ORDER BY
- CASE WHEN @OrderBy = 0
- THEN table.id END ASC,
- CASE WHEN @Orderby = 2
- THEN table.id END ASC,
- CASE WHEN @OrderBy = 4
- THEN (100-((table.price/table.oldprice)*100) as discount END ASC
- SELECT * from [table]
- ORDER BY
- CASE @OrderBy
- WHEN 0
- THEN [table].id -- ASC
- WHEN 2
- THEN [table].id * -1 -- DESC
- ---I want to do something like below as I don't have discount column in table
- WHEN 4
- THEN (100-([table].price/[table].oldprice)*100)
- END
- SELECT *, (100-(table.price/table.oldprice))*100 as discount
- FROM table
- ORDER BY
- CASE WHEN @OrderBy = 0
- THEN table.id END ASC,
- CASE when @orderby=2
- THEN table.id END ASC,
- CASE WHEN @OrderBy = 4
- THEN discount END ASC
- select * from TableName where someCondition >100
- order by
- case when @OrderBy = 'AirlineService'
- then AirlineService END desc,
- case when @OrderBy = 'SomeMore'
- then MyOtherColumn end
- GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement