Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 select query

Author  Topic 

esambath
Yak Posting Veteran

89 Posts

Posted - 2008-09-04 : 03:42:12
Please help this query


Table Name : Employee
-------------------------------
Emp_id Emp_name Emp_age
-------------------------------
1 Peter Doss 24
2 Peter Raj 25
3 Antony 30
4 sam Raj 40
5 sam kumar 25
---------------------------------
OUT PUT : just show the Emp_name
-----------------------------
Emp_name
---------
Peter
Antony
sam

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-04 : 03:46:57
SELECT DISTINCT LEFT(Emp_name,CASE WHEN CHARINDEX(' ',Emp_name) >0 THEN CHARINDEX(' ',Emp_name) ELSE LEN(Emp_name)+1 END -1) FROM YourTable

EDIT:missed a space
Go to Top of Page
   

- Advertisement -