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 |
cgunner
Yak Posting Veteran
95 Posts |
Posted - 2005-07-28 : 09:56:13
|
I have some data that I am trying to import into a table but the raw data has the full name in one column. Has anyone ran across an issue where you had to do an import using DTS from one column to three?Sample:DUFFY, JOHN PDORSEY, ANTHONY WDOLL, DANIEL WDICRESCENZO, RONALD ADENNIS-ESCOFFIER, SHIRLEYDEE, BRUCE DCROSBY, DONALD LCROOK, THOMAS MHILL, CHRISTINE ECREWS, MICHAEL E |
|
Kristen
Test
22859 Posts |
Posted - 2005-07-28 : 10:30:47
|
Pull the data into a staging table and post-process it with SQL into the "actual" table?Splitting names is a minefield ... what happens to L' and La This and people with christian names like Jean-Paul - maybe your data is reliably "Surname then comma then a christian name then optionally space and one initial"??I'll eat my hat if its 100% uniform though (and if not Post Processing it will make it much easier to have several "gos" to catch all the variations)Kristen |
 |
|
cgunner
Yak Posting Veteran
95 Posts |
Posted - 2005-07-28 : 10:59:13
|
How does this look?Function Main()Dim FullNameDim FirstNameDim LastNameDim MidInitialDim SuffixDim PosDim Pos2Dim Pos3 strFullName = DTSSource("Col001") Pos = InStr(1, strFullName, ",", vbTextCompare)If Pos = 0 Then Pos = Len(strFullName) + 1End IfLastName = Trim(Left(strFullName, Pos - 1))Pos2 = InStr(1, LastName, " ", vbTextCompare)If Pos2 Then Pos3 = InStr(Pos2 + 1, LastName, " ", vbTextCompare) If Pos3 Then Suffix = Right(LastName, Len(LastName) - Pos3) LastName = Left(LastName, Pos3 - 1) Else Suffix = Right(LastName, Len(LastName) - Pos2) LastName = Left(LastName, Pos2 - 1) End IfEnd IfPos2 = InStr(Pos + 2, strFullName, " ", vbTextCompare)If Pos2 = 0 Then Pos2 = Len(strFullName)End IfIf Pos2 > Pos Then FirstName = Mid(strFullName, Pos + 1, Pos2 - Pos) MidInitial = Right(strFullName, Len(strFullName) - Pos2)End If'' suffix handling'Select Case UCase(Suffix) Case "JR", "SR", "II", "III", "IV", "MD", "PHD", "PH.D", "M.D." Case Else If Not IsNumeric(Left(Suffix, 1)) Then LastName = LastName & " " & Suffix Suffix = "" End IfEnd SelectDTSDestination("LName") = (LastName)DTSDestination("FName") = (FirstName)DTSDestination("MName") = (MidInitial)DTSDestination("Suffix") = (Suffix) Main = DTSTransformStat_Ok End Function |
 |
|
|
|
|
|
|