SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 sql select part of column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Natalia89
Starting Member

Poland
12 Posts

Posted - 12/05/2013 :  15:28:55  Show Profile  Reply with Quote
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

Poland
12 Posts

Posted - 12/05/2013 :  15:47:58  Show Profile  Reply with Quote

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

India
52309 Posts

Posted - 12/06/2013 :  04:54:00  Show Profile  Reply with Quote
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

Edited by - visakh16 on 12/06/2013 04:54:24
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000