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
 String question

Author  Topic 

mani_12345
Starting Member

35 Posts

Posted - 2012-06-01 : 03:10:53
DECLARE @document varchar(64)

SELECT @document = 'Reflectors$are$vital$safety'

SELECT substring(@document,1,CHARINDEX('$', @document)-1)
GO
in this though i am getting first string bt how can i get secnd string
i like to have individual string ie. output
string 1 : reflectors
string 2 : are
.....

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-06-01 : 03:17:09
use fnParseString from http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76033


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

vinu.vijayan
Posting Yak Master

227 Posts

Posted - 2012-06-01 : 04:57:41
Use a Tally Table to do the split as shown in the following link:

[url]http://www.sqlservercentral.com/articles/T-SQL/62867/[/url]

N 28° 33' 11.93148"
E 77° 14' 33.66384"
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-06-01 : 11:16:56
This is one of the fastest splitters:
http://www.sqlservercentral.com/articles/Tally+Table/72993/
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-06-01 : 12:09:10
quote:
Originally posted by mani_12345

DECLARE @document varchar(64)

SELECT @document = 'Reflectors$are$vital$safety'

SELECT substring(@document,1,CHARINDEX('$', @document)-1)
GO
in this though i am getting first string bt how can i get secnd string
i like to have individual string ie. output
string 1 : reflectors
string 2 : are
.....


if its always four words separated by $ you can use like

DECLARE @document varchar(64)

SELECT @document = 'Reflectors$are$vital$safety'

SELECT parsename(REPLACE(@document,'$','.'),4) as firstword,
parsename(REPLACE(@document,'$','.'),3) as secondword,
parsename(REPLACE(@document,'$','.'),2) as thirdword,
parsename(REPLACE(@document,'$','.'),1) as fourthword


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -