|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Thursday, February 21, 2013 12:01 PM
Points: 149,
Visits: 346
|
|
in my excel sheet i have 1 column
which contains name like
shah, anki S. dogula nanacy baskin brian B waive, FRANCISCO p. le, pinti Leo, tomy
the first one is last name,firstname and middle initial
i need to seperate in all 3 column ,i am using derived column,but dont know expression.
please help me
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 3:47 PM
Points: 1,085,
Visits: 2,188
|
|
How about this? It might be expensive, but it's a solution.
WITH names( fullname) AS( SELECT 'shah, anki S.' UNION ALL SELECT 'dogula nanacy' UNION ALL SELECT 'baskin brian B' UNION ALL SELECT 'waive, FRANCISCO p.' UNION ALL SELECT 'le, pinti' UNION ALL SELECT 'Leo, tomy'), names2 AS( SELECT REPLACE(REPLACE(REPLACE(fullname, '.',''),',', ''), ' ', '.') AS formatname FROM names ) SELECT REVERSE( PARSENAME(REVERSE(formatname), 1)), REVERSE( PARSENAME(REVERSE(formatname), 2)), REVERSE( PARSENAME(REVERSE(formatname), 3)) FROM names2
Or you can do it all at once:
WITH names( fullname) AS( SELECT 'shah, anki S.' UNION ALL SELECT 'dogula nanacy' UNION ALL SELECT 'baskin brian B' UNION ALL SELECT 'waive, FRANCISCO p.' UNION ALL SELECT 'le, pinti' UNION ALL SELECT 'Leo, tomy' ) SELECT REVERSE( PARSENAME(REVERSE(REPLACE(REPLACE(REPLACE(fullname, '.',''),',', ''), ' ', '.')), 1)), REVERSE( PARSENAME(REVERSE(REPLACE(REPLACE(REPLACE(fullname, '.',''),',', ''), ' ', '.')), 2)), REVERSE( PARSENAME(REVERSE(REPLACE(REPLACE(REPLACE(fullname, '.',''),',', ''), ' ', '.')), 3)) FROM names
Luis C. Please don't trust me, test the solutions I give you before using them. Forum Etiquette: How to post data/code on a forum to get the best help
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Thursday, February 21, 2013 12:01 PM
Points: 149,
Visits: 346
|
|
| i need derived column solution ,not sql
|
|
|
|
|
SSCarpal Tunnel
       
Group: General Forum Members
Last Login: Today @ 1:10 PM
Points: 4,319,
Visits: 9,658
|
|
harri.reddy (8/29/2012) i need derived column solution ,not sql
Write out your detailed logic for breaking the column into three and we'll help with the solution. Might need a Script Component if it's complex - derived columns can only go so far.
____________________________________________________________________________________________
Help us to help you. For better, quicker and more focused answers to your questions, consider following the advice in this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
If you are asking for help and your post does not contain a question, you should expect responses which do not contain any answers. Put a question mark in there somewhere - it's not rocket science.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 3:47 PM
Points: 1,085,
Visits: 2,188
|
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Thursday, February 21, 2013 12:01 PM
Points: 149,
Visits: 346
|
|
i am usinf this expression for my first column
REPLACE(SUBSTRING(product,1,FINDSTRING(product," ",1) + 0),","," ")
i need help for second and third.
please help me
|
|
|
|
|
SSCarpal Tunnel
       
Group: General Forum Members
Last Login: Today @ 1:10 PM
Points: 4,319,
Visits: 9,658
|
|
harri.reddy (8/29/2012) i am usinf this expression for my first column
REPLACE(SUBSTRING(product,1,FINDSTRING(product," ",1) + 0),","," ")
i need help for second and third.
please help me
Not really what I asked for. What is your logic for dividing the second and third columns? It needs to accommodate all the variations in your data.
____________________________________________________________________________________________
Help us to help you. For better, quicker and more focused answers to your questions, consider following the advice in this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
If you are asking for help and your post does not contain a question, you should expect responses which do not contain any answers. Put a question mark in there somewhere - it's not rocket science.
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Thursday, February 21, 2013 12:01 PM
Points: 149,
Visits: 346
|
|
i know ,it has so many variation.
what is the other way in ssis, i can achieve.
plz help me
|
|
|
|
|
SSCarpal Tunnel
       
Group: General Forum Members
Last Login: Today @ 1:10 PM
Points: 4,319,
Visits: 9,658
|
|
harri.reddy (8/29/2012) i know ,it has so many variation.
what is the other way in ssis, i can achieve.
plz help me
Ah, you must mean the magic-wand component.
____________________________________________________________________________________________
Help us to help you. For better, quicker and more focused answers to your questions, consider following the advice in this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
If you are asking for help and your post does not contain a question, you should expect responses which do not contain any answers. Put a question mark in there somewhere - it's not rocket science.
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Today @ 2:10 PM
Points: 35,
Visits: 84
|
|
This should help : Have a derived col. Have three cols in there as (assume F1 is your excel col):
First_name expression :SUBSTRING((REPLACE(F1,","," ")),1,FINDSTRING(F1," ",1))
Last_name expression : SUBSTRING(F1,FINDSTRING(F1," ",1) + 1,FINDSTRING(F1 + " "," ",2) - FINDSTRING(F1," ",1) - 1)
middle_name expression : (FINDSTRING(F1," ",2) > 0) ? REPLACE(SUBSTRING(F1,FINDSTRING(F1," ",2) + 1,FINDSTRING(F1 + " "," ",3) - FINDSTRING(F1," ",2) - 1),".","") : " "
Please let me know if this worked or not
|
|
|
|