I’m importing a table which is supposed to have an integer primary key, but the data is messy and we find things like “6TEST3” or “CREDIT3” in this field. I want to read the table and use this field as an integer, however can’t convert it because of those rows.
Is there a way to remove a row if I can’t convert a field value to integer?
Filter table on data type of column
Best answer by rogier.helmus
Hi
Let's say your primary key field is the AdressID of a table with addresses, you could apply a data selection rule on the mapped table that only loads rows for which the primary key field is a numerical value. Example:

This works if I put the following values in the AddressWithAdressIdVarchar table:

Row 1 is loaded, but rows 2 and 3 are not.
However, you have to be mindful that the ISNUMERIC() function might not be fully working for your dataset. There are characters that the function will characterize is being numeric and that will fail when you put that value in an integer field. This issue is better explained in this article: https://www.sqlshack.com/an-overview-of-the-sql-server-isnumeric-function/ . The article also has 2 alternatives for the ISNUMERIC function at the end.
Hope this helps!
Kind regards, Rogier
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.