ScottParker
asked on
SQL statement in mySQL and VB.net
Hello
VB.net 2005
mySQL 4.1 backend database
I have the following sql statement
Select userid, catcode01, firstname, lastname from users where userid = 5
the value that is stored in the user table for catcode01 is a number 1-10.
Without making another table, and doing a join to it, is there a way in the SQL statement to show some text instead of or in addition to the catcode01 field?
example returned record
123 1 john doe
124 1 jane doe
125 2 frank smith
what I would like it to show is..
123 1-Sales john doe
124 1-Sales jane doe
125 2-Accounting frank smith
VB.net 2005
mySQL 4.1 backend database
I have the following sql statement
Select userid, catcode01, firstname, lastname from users where userid = 5
the value that is stored in the user table for catcode01 is a number 1-10.
Without making another table, and doing a join to it, is there a way in the SQL statement to show some text instead of or in addition to the catcode01 field?
example returned record
123 1 john doe
124 1 jane doe
125 2 frank smith
what I would like it to show is..
123 1-Sales john doe
124 1-Sales jane doe
125 2-Accounting frank smith
Try this
Select userid+' '+case catcode01 when 1 then 'Sales' when 2 then 'Accounting' else 'unknown' end +' '+firstname+' '+ lastname from users where userid = 5
You can add more value of catcode01
HuyBD;
Select userid+' '+case catcode01 when 1 then 'Sales' when 2 then 'Accounting' else 'unknown' end +' '+firstname+' '+ lastname from users where userid = 5
You can add more value of catcode01
HuyBD;
Hi ScottParker
try the following:
SELECT CONCAT( userid, " ", catcode01, " ", firstname, " ", lastname) FROM users WHERE userid = 5
try the following:
SELECT CONCAT( userid, " ", catcode01, " ", firstname, " ", lastname) FROM users WHERE userid = 5
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect. Just what I was looking for.
Select userid, if(catcode01=1,'1-Sales', if(catcode01=2, '2-Accounting','Other') ) catDEtail, , firstname, lastname from users where userid = 5