We help IT Professionals succeed at work.

'as' blocks

sasha85
sasha85 asked
on
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")...
Comment
Watch Question

Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009
Commented:
>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

Author

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

mysql="?"
Top Expert 2008
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"

Open in new window

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

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...
Top Expert 2008
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"

Open in new window

Author

Commented:
I FOUND THE PROB...there was (') missing in the 3 part...

Author

Commented:
ok than...how now i can print all the abc records first and then all the def?

Author

Commented:
i mean in 2 groups...

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?

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...
Guy Hengel [angelIII / a3]Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009
Commented:
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.
Top Expert 2008
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')"

Open in new window

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
...
Guy Hengel [angelIII / a3]Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009

Commented:
please explain more, what data you have as input in the column. just so we understand...
what is the div's about...

Author

Commented:
sorry i dropped this idea

Explore More ContentExplore courses, solutions, and other research materials related to this topic.