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.
| Author |
Topic |
|
anjali5
Posting Yak Master
121 Posts |
Posted - 2011-11-30 : 12:40:44
|
| Table ACol1 col2 Col3 col4 col5 12 456 A, B, C, D Ware, TELL, RAW QUEST, TIME, RAN, PEEK 13 987 W,E,R, D YES, TAP, WEE, TEE NEWS, JACK, LAN, BELLI have this table, I need to get the data like this12 456 A WARE QUEST12 456 B TELL TIME12 456 C RAW RAN12 456 D PEEK13 987 W YES NEWS13 987 E TAP JACK13 987 R WEE LAN13 987 D TEE BELLBasically, I want all the comma delimited from col3 and corresponmding comma delimited from col4 so A is related to ware and B is related to TELL and C is related to RAW.Also, i want the col5 to be parsed to seperate rows.Any help will be appreciated. |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
anjali5
Posting Yak Master
121 Posts |
Posted - 2011-11-30 : 13:11:16
|
| The data model is not normalized. I am trying to do that. This is the legacy data that I getting from some other old database. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
anjali5
Posting Yak Master
121 Posts |
Posted - 2011-11-30 : 13:24:26
|
| I just need a table called Table Aand all the comma delimited column data in seperate rows. The only thing is whoever designed the original database have col3 related to col4if col3 has A in it, I want WARE in col4, I don't want TELL in Col4, if Col3 has A in it. |
 |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2011-11-30 : 14:28:39
|
An example of the table UDF that Brett referred to is available here: http://www.sqlservercentral.com/articles/Tally+Table/72993/Copy and run the script in Fig. 21 on that page to install the function on your database. Then, your query would be something like this:SELECT t1.col1, t1.col2, c3.*FROM TableA t1 CROSS APPLY dbo.DelimitedSplit8K(col3,',') C3 That handles only one of the comma-delimited columns. You can replicate that for each of the other comma-delimited columns and join all three. |
 |
|
|
|
|
|
|
|