Use this:
create table person
(
name varchar(50)
);
insert into person(name)
select 'John' union
select 'Paul' union
select 'George' union
select 'Ringo' ;
set @direction = 1;
select * from person
order by
IF (@direction = 0, name,'') ASC,
IF (@direction = 1, name,'') DESC
Live test: http://www.sqlfiddle.com/#!2/22ea1/1
- -1 , +1 , , :
create table person
(
name varchar(50), birth_year int
);
insert into person(name, birth_year)
select 'John', 1940 union
select 'Paul', 1941 union
select 'George', 1943 union
select 'Ringo', 1940 ;
set @direction = -1;
select * from person
order by birth_year * @direction
Live test: http://www.sqlfiddle.com/#!2/f78f3/3