Hi,
I have a list of names that I want to concatenate them with a seperator (comma) (please see below), constrained to following criteria
1- Remove all dots spaces from middle initial
2-If there is no middle initial, it should look like Adam, Thomas not Adam, Thomas, ---> No comma at the end
3-Same procedure applies to first Name . If there is no FIrst Name, just include last name with no comma
Expect outcome should look like below. Not sure If i can do it with formula function by using if else (or something else) statement. Any help is appreciated
First Name | Last Name | Middle Initial | Output |
Tom | Jack | D.R | Tom,Jack,DR |
Skura | Daniel | Skura,Daniel | |
Tim | Treak | F | Tim,Treak |
Tim | Howard | Tim,Howard | |
Simmons | Simmons |
Solved! Go to Solution.
Probably the simplest way is to use the Data Cleansing tool to remove the spaces and . etc as initial clean up step.
You can then use a formula tool to make the concatenated string:
[Last Name] + IIF(IsNull([First Name]) || [First Name] = '', '', ', ' + [First Name]) + IIF(IsNull([Middle Initial]) || [Middle Initial] = '', '', ', ' + [Middle Initial])
You can do this in one step using the REGEX_Replace function to clean up:
REGEX_Replace([Last Name], '[^A-Za-z]', '') + IIF(IsNull([First Name]) || REGEX_Replace([First Name], '[^A-Za-z]', '') = '', '', ', ' + REGEX_Replace([First Name], '[^A-Za-z]', '')) + IIF(IsNull([Middle Initial]) || REGEX_Replace([Middle Initial], '[^A-Za-z]', '') = '', '', ', ' + REGEX_Replace([Middle Initial], '[^A-Za-z]', ''))
Sample attached
Thanks for sharing the + SIGN tip for concatenation. I also appreciate the REGEX_WITH REPLACE. The second item is very useful and nicely explained.
Abhay,
This works and thanks for your help. I removed the pipes ( || ) from my Teradata SQL and used the +.
David