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)
 Select everything after specific character

Author  Topic 

sqlnovice1
Starting Member

34 Posts

Posted - 2011-07-29 : 06:06:40
Hi

I have a string in a field from which i need to do a select.

My field contains the following ...

S72.00,W19.0,M16.9,Z86.7

How can i do a sleect only looking at this section of the string

.......W19.0,M16.9,Z86.7

The length of field coudl be anything upto 250 characters and all items in the string will always be seprated by a ,

Thanks in advance for any help.


Paul

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-07-29 : 07:21:06
Let's see. Everything after the first comma? Everything after the item marked S? Everything from the 8th position to the end?

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

sqlnovice1
Starting Member

34 Posts

Posted - 2011-07-29 : 07:35:41
Hi Jim

It will always be everthing after the first comma. It may not always be in the 8th position.

Thanks
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-07-29 : 08:07:46
Here ya go.

Jim
declare @string varchar(250)
set @string = 'S72.00,W19.0,M16.9,Z86.7'
select substring(@string,charindex(',',@string)+1 ,250)

Everyday I learn something that somebody else already knew
Go to Top of Page

sqlnovice1
Starting Member

34 Posts

Posted - 2011-07-29 : 08:31:51
Thanks very much Jim, Great help. thanks for speeedy reply.
Go to Top of Page
   

- Advertisement -