Link to home
Start Free TrialLog in
Avatar of ScottParker
ScottParkerFlag for United States of America

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
Avatar of appari
appari
Flag of India image

may be something like this

Select userid, if(catcode01=1,'1-Sales', if(catcode01=2, '2-Accounting','Other') ) catDEtail, , firstname, lastname from users where userid = 5
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;
Hi ScottParker

try the following:

SELECT CONCAT( userid, " ", catcode01, " ", firstname, " ", lastname) FROM users WHERE userid = 5
ASKER CERTIFIED SOLUTION
Avatar of HuyBD
HuyBD
Flag of Viet Nam image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ScottParker

ASKER

Perfect.  Just what I was looking for.