# 'as' blocks

i need to set a query with

left(uname,1)='a' or left(uname,1)='b' or left(uname,1)='c' AS abc
,left(uname,1)='d' or left(uname,1)='e' or left(uname,1)='f' AS def

some thing like this that i will be able to print as
response.write rs("abc")...
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Billing EngineerCommented:
>left(uname,1)='a' or left(uname,1)='b' or left(uname,1)='c'
this is a condition, what do you want to be returned?

let me guess:
 CASE WHEN left(uname,1) IN('a','b',c') then uname else null end AS abc
,CASE WHEN left(uname,1) IN('d','e',f') then uname else null end AS abc

0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
yes...but how can i set it inside sql query?

mysql="?"
0
Commented:
just copy the code by angelIII and add a "SELECT" at the start and a "FROM urtable" at the end
mysql="SELECT CASE WHEN left(uname,1) IN('a','b',c') then uname else null end AS abc,CASE WHEN left(uname,1) IN('d','e',f') then uname else null end AS def FROM Table"

0
Author Commented:
mysql="SELECT CASE WHEN left(uname,1) IN('ó','ó',ó') then uname else null end AS abc,CASE WHEN left(uname,1) IN('ó','ó',ó"') then uname else null end AS def FROM demo_users"

MySQL][ODBC 3.51 Driver][mysqld-4.1.21-community-nt]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '×') then uname else null end AS abc,CASE WHEN left(uname,1) IN('×','×',×"') t' at line 1
0
Author Commented:
i mean
mysql="SELECT CASE WHEN left(uname,2) IN('ó','ó',ó') then uname else null end AS abc,CASE WHEN left(uname,2) IN('ó','ó',ó"') then uname else null end AS def FROM demo_users"

left(uname,2)

cause there are 2 chars...

but still this is query syntax...
0
Commented:
sorry, missed one '


mysql="SELECT CASE WHEN left(uname,1) IN('a','b','c') then uname else null end AS abc,CASE WHEN left(uname,1) IN('d','e','f') then uname else null end AS def FROM Table"

0
Author Commented:
I FOUND THE PROB...there was (') missing in the 3 part...
0
Author Commented:
ok than...how now i can print all the abc records first and then all the def?
0
Author Commented:
i mean in 2 groups...
0
Author Commented:
do i realy need to run on the all records 2 time ?
first to take out the abc and second time for the def?
or there is better way?
0
Author Commented:
if i will just
response.write "abc:" & xabc & "<br>"
response.write "def:" & xdef & "<br>"

it will print <br> instead of records wich got no abc or def...
0
Billing EngineerCommented:
so, you actually want all the ABC first, then the DEF etc?
but then, why 2 fields?

can you, just to get the complete picture of what you are trying to achieve, explain us what you are trying to achieve.
0
Commented:
since you have 2 columns, 1 for the abc and 1 for the def, you will have to loop through all the records of rs("abc") check if its value is not null, then print. then do this again for the rs("def")

you could also modify the query to the one below so that rs("uname") will have all the records with uname that start with a/b/c. then modify the IN ('a','b','c') to IN ('d','e','f') to get the records with uname that start with d/e/f, etc...

"SELECT CASE uname FROM demo_users WHERE left(uname,1) IN('a','b',c')"

0
Author Commented:
i got only one column...wich i want to divide into abc\def...
my plan is to print each rs("abc"),rs("def")...into diffrent div..
<div id=abc
<div id=def
...
0
Billing EngineerCommented:
please explain more, what data you have as input in the column. just so we understand...