Click here to Skip to main content
15,937,779 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I am trying to retrieve the emp_id from my table by using a combination on first and last name, actually in my app i m allowing the user to select name from a list box, and filling the list box from the user_details table from first and last name column with a space in between, i.e. "Mohit Roy", if the user select the name i want my app to do some operation using the emp_id of that name, please help me to write the query which can retrieve the emp_id using first and last name column with a space between in it. Thanks in advance.
Posted

1 solution

Mysql:

SELECT CONCAT_WS(' ', `name`, `surname`) AS `emp_id` FROM `employees`


PostgreSQL:

SELECT name || ' ' || surname FROM employees


SQLServer 2005:

SELECT name + ' ' + surname FROM employees


check this ;)
 
Share this answer
 
v2
Comments
souvikd 20-Aug-10 5:39am    
hi thanks for replying but it doesnt work, i m trying to do this , please check the following
select emp_id from user_details where first_name +''+ last_name = 'Mohit Roy'
Nyarost 20-Aug-10 5:43am    
don't have SQLServer 2005 near. In MySQL following works:
SELECT * FROM `gifts` WHERE CONCAT_WS(' ', `from`, `ts`) = '1 1'

try:
SELECT (name + ' ' + surname) AS emp_id FROM employees WHERE emp_id = 'Mohit Roy'

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900