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
 split string!

Author  Topic 

maevr
Posting Yak Master

169 Posts

Posted - 2011-03-15 : 10:26:27
Need help splitting string from column signa so that all characters ends up on a separate rows in an new table maintaining id and nr.
signa can contain multiple characters ABC, HHSS, HAHAH and so on.

expected output:
id nr signa
1, '1000001', 'ABC'
1, '1000001', 'VQW'
2, '1000002', 'GJO'
2, '1000002', 'EOO'
.
.
.


create table #testKBV
(
id int not null
,nr varchar(10) not null
,signa varchar(20) null
)

DROP TABLE #testKBV

insert into #testKBV(id, nr, signa) values(1, '1000001', 'ABC, VQW, TTT')
insert into #testKBV(id, nr, signa) values(2, '1000002', 'GJO, EOO')
insert into #testKBV(id, nr, signa) values(3, '1000003', 'QQQ, LLL, MQP')
insert into #testKBV(id, nr, signa) values(4, '1000004', 'ABP, ZAS, AWE')
insert into #testKBV(id, nr, signa) values(5, '1000005', 'ABC')
insert into #testKBV(id, nr, signa) values(6, '1000006', 'OPP, EEE, LLL')
insert into #testKBV(id, nr, signa) values(7, '1000007', 'UWG, III')
insert into #testKBV(id, nr, signa) values(8, '1000008', 'GTR, DAS, UVV')
insert into #testKBV(id, nr, signa) values(9, '1000009', 'MNB, ASD, ERT')

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-03-15 : 10:34:35
Search this site for fnParseValues, it takes a delimited string and returns the elements in a table.

Jim

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

- Advertisement -