I need to write a table-valued function in T-SQL that would take a zip code in any string format and output two integers for the first five-digit and the second four-digit parts of the zip code.
The input can look like this: “123456787432”, in which case only first 9 digits should be taken into account.
Or it can look like this: “12345-4567”, or like this: “12345”, in which case the second part output should be 0.
Or it may have any garbage characters among the digits, which characters should be ignored.
If the second part is “0345”, the output should be 345.
If there was an efficient way to filter out all non-numeric characters, the rest would be very easy.
I will appreciate any suggestions.
Don’t know about efficient but this is a way.