How to detect extra columns or missing columns
Sometimes, we need to validate the input columns to check if there are some extra columns or missing columns in SSIS. ZappySys includes some pretty nice tools, but some of them cannot check the required values. To fix that problem, you can complement these tools with our Regular Expression Parser Task.
We will use Regular Expressions to validate the columns. For example, we want to check that the file has 3 columns with specific names, if it contains extra columns or there are missing some columns, we want to send an error. We will show now how to do this.
We will be using this ZappySys SSIS PowerPack component to make things work:
Prerequisites
Before we perform the steps listed in this article, you will need to make sure the following prerequisites are met:- SSIS designer installed. Sometimes it is referred to as BIDS or SSDT (download it from the Microsoft site).
- Basic knowledge of SSIS package development using Microsoft SQL Server Integration Services.
- Make sure ZappySys SSIS PowerPack is installed (download it, if you haven't already).
- (Optional step). Read this article, if you are planning to deploy packages to a server and schedule their execution later.
Creating a CSV file
- In order to start, we will create a CSV file with some columns. Create a file named document.csv or any name of your preference.
- Add data similar to the following:
123name,lastname,emailClint,Eastwood,ceastwood@gmail.comCameron,Diaz,cdiaz@gmail.com
Create a connection in SSIS
- First of all, SSDT, open an SSIS project.
- Secondly, in the connection manager, right-click and select a new file connection.
- In the Connection, select the CSV file created before:
ZS Regular Expression Parser to detect missing columns in SSIS
- Now, it is time to use the ZS Regular Expression Parser.
- Secondly, drag and drop the ZS Regular Expression in the design pane:
- Also, open the task and select the connection in the ZS Regular Expression task.
- In addition, add the following expression in the Task:
1^name,lastname\r\n
- In the previous scenario, the expression will fail because it is missing the email.
- Finally, the following Expression will pass, because the email is included.
Conclusion
In this article, we learned how to validate and check the columns in a file in ZappySys using the ZS Regular Expression Parser. In the example, we created an expression to detect an exact match of columns. It will raise an error in case of a failure.
If you want to enjoy this and other ZappySys tools, you can download our product here.