This site uses different types of cookies, including analytics and functional cookies (its own and from other sites). To change your cookie settings or find out more, click here. If you continue browsing our website, you accept these cookies.
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
Go to Solution.
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:
+ 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]', ''))
Thanks for sharing the + SIGN tip for concatenation. I also appreciate the REGEX_WITH REPLACE. The second item is very useful and nicely explained.
Parse Error at char(153): Malformed IF statement (Expression #2)
[LN_ID] + "-" + [GL_MATRIX] + "-" +IF [HfsFlag]="Y"then "HFS"elseif [HfsFlag]="N"then "HFI" else ""+IF [FvoFlag] = "Y" THEN "-FVO"ELSE ""ENDIF
This works and thanks for your help. I removed the pipes ( || ) from my Teradata SQL and used the +.