Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

derived column Expand / Collapse
Author
Message
Posted Wednesday, August 29, 2012 10:54 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-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
Post #1351767
Posted Wednesday, August 29, 2012 11:57 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen 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
Post #1351801
Posted Wednesday, August 29, 2012 12:09 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-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
Post #1351810
Posted Wednesday, August 29, 2012 12:14 PM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal 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.
Post #1351816
Posted Wednesday, August 29, 2012 12:22 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 3:47 PM
Points: 1,085, Visits: 2,188
I'm sorry, I didn't see the forum's name


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
Post #1351826
Posted Wednesday, August 29, 2012 12:53 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-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
Post #1351855
Posted Wednesday, August 29, 2012 1:25 PM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal 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.
Post #1351878
Posted Wednesday, August 29, 2012 1:51 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-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
Post #1351896
Posted Wednesday, August 29, 2012 2:17 PM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal 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.
Post #1351905
Posted Wednesday, August 29, 2012 7:51 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC 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


Post #1351979
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse