I have in Teradata SQL table like below:
col1 | col2
----------------------------
Adam Nowak PHU | Nowak Adam
AAR Kowal Jan | Kowal Jan
Tomasz Gut | Juk Anna
And I would like to select only these rows where:
- in col1 I have value from col2 + something (nevermind before or after value)
- Be aware that order of name and surname is not important so Jan Kowal is the same that Kowal Jan
So as a result I need something like below, so only first and second rows because there are in col1 value from col2 + something else and order of name and surname is not important:
I used query like below, but my query does not take into account that order of name and surname is not important and for my code Jan Kowal and Kowal Jan are different persons.
where upper(col1) like '%' || upper(col2) || '%'
Moreover I used code which was perfect to my case and work correctly but only on MS SQL Server, on Teradata SQL id does not work:
WHERE
upper(col1) LIKE '%' + substring(upper(col2), 1, CHARINDEX(' ',col2)-1) + '%'
AND
upper(col1) LIKE '%' + substring(upper(col2), CHARINDEX(' ',col2)+1, LEN(col2)) + '%'
How can I do taht in Teradata SQL? Could you modify my code which work on MS SQL Server or suggest your own solution which work on Teradata SQL ?