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
 sql select part of column

Author  Topic 

Natalia89
Starting Member

12 Posts

Posted - 2013-12-05 : 15:28:55
how do i only display a part of data from the column
lets say emp_id is E3456 and all i want to display is 3456 without that E? any ideas?

saddf

Natalia89
Starting Member

12 Posts

Posted - 2013-12-05 : 15:47:58

SELECT SUBSTRING( e.emp_id,2,4) AS supervisor, e.name
FROM employee e
WHERE exists (SELECT 1 from employee WHERE supervisor = e.emp_id)
ORDER BY name;

saddf
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-12-06 : 04:54:00
More genric solution
will work for any length numbers and also when length of alphabetical part also varies

SELECT STUFF( e.emp_id,1,PATINDEX('%[0-9]%',e.emp_id)-1,'') AS supervisor, e.name
FROM employee e
WHERE exists (SELECT 1 from employee WHERE supervisor = e.emp_id)
ORDER BY name;


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -