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)
 Separating Strings into temp table

Author  Topic 

Kalaiselvan
Posting Yak Master

112 Posts

Posted - 2012-01-07 : 00:11:12
Hi,
I need the solution for taking string values into temp table using charindex and sub_string.

Ex: Text='field_1=A-field_2=B-field_3=C'

Needed Output:
A,B,C --> In a table [COLUMN]
A
B
C

Regards,
Kalaiselvan R
Love Yourself First....

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-07 : 00:46:10
see

http://visakhm.blogspot.com/2010/02/parsing-delimited-string.html

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

Go to Top of Page

Kalaiselvan
Posting Yak Master

112 Posts

Posted - 2012-01-07 : 04:28:21
Visakh,
Your link used with Delimitter, were as my example needs a start and end value to seperate the string.
Bcoz Field names is increemented. I need thw in between letters from = and -.

Regards,
Kalaiselvan R
Love Yourself First....
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-07 : 08:20:10
quote:
Originally posted by Kalaiselvan

Visakh,
Your link used with Delimitter, were as my example needs a start and end value to seperate the string.
Bcoz Field names is increemented. I need thw in between letters from = and -.

Regards,
Kalaiselvan R
Love Yourself First....


your sample data shows A,B,C which is delimited didnt understand what you mean by field in between

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

Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2012-01-08 : 03:28:23
quote:
Originally posted by Kalaiselvan

Visakh,
Your link used with Delimitter, were as my example needs a start and end value to seperate the string.
Bcoz Field names is increemented. I need thw in between letters from = and -.


You have a delimiter "-field_", and you also have a leading string "field_" which you will need to remove before splitting the remainder. You need a Splitter function that allows a delimiter to be multi-character, and for Row & Column delimiters to be different, or you could first REPLACE "-field_" with "=" and then you would have "1=A=2=B=3=C" (after removing leading "field_") and then you can use a single-character delimiter to split on "=" and take every alternate value.
Go to Top of Page
   

- Advertisement -