'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")...
sasha85Asked:
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.

Guy Hengel [angelIII / a3]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

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

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

Start your 7-day free trial
sasha85Author Commented:
yes...but how can i set it inside sql query?

mysql="?"
0
ee_rleeCommented:
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"

Open in new window

0
Newly released Acronis True Image 2019

In announcing the release of the 15th Anniversary Edition of Acronis True Image 2019, the company revealed that its artificial intelligence-based anti-ransomware technology – stopped more than 200,000 ransomware attacks on 150,000 customers last year.

sasha85Author 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
sasha85Author 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
ee_rleeCommented:
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"

Open in new window

0
sasha85Author Commented:
I FOUND THE PROB...there was (') missing in the 3 part...
0
sasha85Author Commented:
ok than...how now i can print all the abc records first and then all the def?
0
sasha85Author Commented:
i mean in 2 groups...
0
sasha85Author 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
sasha85Author 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
Guy Hengel [angelIII / a3]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
ee_rleeCommented:
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')"

Open in new window

0
sasha85Author 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
Guy Hengel [angelIII / a3]Billing EngineerCommented:
please explain more, what data you have as input in the column. just so we understand...
what is the div's about...

0
sasha85Author Commented:
sorry i dropped this idea
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.