Click here to Skip to main content
15,889,595 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
please help me
i am working with access database in vb 6
i want to conditional order by in select command with a varriable value

exp
dim sortonname as Boolean

i want to order by according to varriable if true then
order by name else default

SQL
select * from students iif(sortonname=true,order by name,order by city(default))
Posted
Updated 12-May-12 20:50pm
v2

Don't have access at hand to test this, but you could try something like
SQL
select * from students order by iif(sortonname=true, name, city)
 
Share this answer
 
Assuming that you set sortonname as a VB variable, pass it though to Access as a parameter (@SortOnName below) and try this:
SQL
IF @SortOnName=0
   SELECT * FROM students ORDER BY city
ELSE
   SELECT * FROM students ORDER BY name
 
Share this answer
 
Comments
Maciej Los 13-May-12 4:55am    
Good answer! +5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900