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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 parsing data after _

Author  Topic 

sharona
Yak Posting Veteran

75 Posts

Posted - 2011-05-05 : 15:37:31
if i have a field that displays like this

o394772_yuj9003

how do i get the information after the _
do i use instr()????

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-05-05 : 15:39:04
DECLARE @s varchar(25)

SET @s = 'o394772_yuj9003'

SELECT SUBSTRING(@s, CHARINDEX('_', @s)+1, LEN(@s))

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-05-05 : 15:39:47
SELECT RIGHT(@s, LEN(@s) - CHARINDEX('_', @s))

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

ms65g
Constraint Violating Yak Guru

497 Posts

Posted - 2011-05-05 : 15:44:02
select PARSENAME(replace(@s,'_','.'),1)

______________________
Go to Top of Page
   

- Advertisement -