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 2005 Forums
 Transact-SQL (2005)
 Separate Words In Sentence

Author  Topic 

Brittney10
Posting Yak Master

154 Posts

Posted - 2012-12-10 : 17:32:44
I need to be able to separate words in a sentence and insert them as their own record. For example, I have a record that needs inserted:


ID_____Name (str)
1______Name One
2______Name Two
3______Name Three


I need 6 records to be inserted from the above 3 records (note the IDs)

ID_____Name (str)
1______Name
1______One
2______Name
2______Two
3______Name
3______Three


Any help or direction on this would be greatly appreciated. I'm actually trying to achieve this in SSIS, but figured I could also do it in SQL as well.

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-12-10 : 18:59:44
SSIS is probably a better place for this kind of thing. But, if you want to do it in SQL then one option is to get Parse/Split function. Here is one of the better ones:
http://www.sqlservercentral.com/articles/Tally+Table/72993/
Go to Top of Page

Brittney10
Posting Yak Master

154 Posts

Posted - 2012-12-11 : 09:02:32
I would prefer to do it in SSIS, if you have a good idea of how to do this?
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-12-11 : 11:41:18
Here is one example, if you do a search you'll find many more:
http://bi-polar23.blogspot.com/2008/06/splitting-delimited-column-in-ssis.html
Go to Top of Page
   

- Advertisement -