Validate multiple columns in a csv file

Anonymous
2023-07-10T12:42:50.73+00:00

Am loading a CSV file to a landing table , the problem is i have to check if some of the columns in the file are numeric or not , if they are not numeric the file should be sent to the error folder .If not they file must be processed to the landing table . Can i get some help , how do i achieve this using SSIS package.

SQL Server Integration Services
SQL Server | Other
0 comments No comments
{count} votes

Answer accepted by question author
  1. ZoeHui-MSFT 41,536 Reputation points
    2023-07-11T06:49:32.69+00:00

    Hi @Mfezeko Donald Sodawe,

    You may use expression to check columns in the file are numeric or not.

    (DT_I4)data == (DT_I4)data ? (DT_I4)data : NULL(DT_I4)

    And then you may use precedence constraint to load data or remove the file.

    User's image

    Regards,

    Zoe Hui


    If the answer is helpful, please click "Accept Answer" and upvote it.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Yitzhak Khabinsky 27,091 Reputation points
    2023-07-10T13:21:29.84+00:00

    Hi @Mfezeko Donald Sodawe,

    *.csv/txt flat files always have host of problems where column delimiters, column separators, invisible characters like null terminators \0, special characters based on encoding, and line breaks are in the middle of the actual data. Or data elements are missing completely.

    The most reliable format for data feeds is XML enforced by an XSD. An XSD plays a role of a data contract between sender and receiver. It will guarantee proper data format/shape, data types, cardinality, and enforce data quality.

    SSIS has XML Task, OperationType Validate, to validate XML file against the XSD: https://learn.microsoft.com/en-us/sql/integration-services/control-flow/validate-xml-with-the-xml-task?view=sql-server-ver16

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.