| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-07-10 : 09:08:16
|
| writes "Hi DB Experts,Good evening! I have a problem. I have a namelist coming from a distribution list of an active directory. When I converted it to csv file, the members reside in just one column and separated by a comma. I want the names to be separated in a row one by one. I tried it on excel and use the transpose function but to no avail. My last resort is to import it on sql but the names in the column was cut and incomplete. Do you have any idea how to do this. Your help is highly appreciated.this is the sample file..nameskelly.yap, lizzy.fox, yahoo, finance.dep, hope.miller, porly.john the maximum names in a row is 566.thanks in advance." |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
RyanRandall
Master Smack Fu Yak Hacker
1074 Posts |
Posted - 2006-07-10 : 11:21:22
|
If you need to 'split' for multiple rows, using a numbers/tally table is one approach.Here's an example...  --datadeclare @names table (id int, v varchar(8000))insert @names select 1, 'kelly.yap, lizzy.fox, yahoo, finance.dep, hope.miller, porly.john'union all select 2, 'this, is, another, line, of, text, some, values, have, two words, others have three'union all select 3, 'this, is, a, third, line'--calculationselect id, ltrim(substring(v, NUMBER, charindex(',', substring(v + ',', NUMBER, 8000))-1)) as namefrom dbo.F_TABLE_NUMBER_RANGE(1, 8000), @nameswhere substring(',' + v, NUMBER, 1) = ','order by id/*resultsid name ----------- ---------------------------1 kelly.yap1 lizzy.fox1 yahoo1 finance.dep1 hope.miller1 porly.john2 this2 is2 another2 line2 of2 text2 some2 values2 have2 two words2 others have three3 this3 is3 a3 third3 line*/You can find F_TABLE_NUMBER_RANGE here:http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=47685Ryan Randallwww.monsoonmalabar.com London-based IT consultancy Solutions are easy. Understanding the problem, now, that's the hard part. |
 |
|
|
|
|
|