Published on

December 9, 2020

How to Use Iterations and Conditions Activities in SQL Server

Welcome to another article on SQL Server! In this article, we will explore how to use iterations and conditions activities in SQL Server to work with different data stores and validate the data stored in these stores.

Overview

In SQL Server, iterations and conditions activities are powerful tools that allow you to perform specific actions based on certain conditions. These activities can be used in various scenarios, such as copying data between different data stores, transforming data, and running SSIS packages.

Creating a Pipeline

To demonstrate the usage of iterations and conditions activities, let’s create a pipeline that reads data stored in CSV files located in an Azure Blob Storage container and writes the data to an Azure SQL Database table.

First, we need to create the source and sink linked services and datasets. The source linked service will point to the Azure Blob Storage container where the CSV files are stored, while the sink linked service will point to the Azure SQL Database where the data will be written.

Next, we will add activities to the pipeline. We will start with the Get Metadata activity, which retrieves the list of source files and their names. We will then use the Filter activity to pass only the files with a CSV extension.

After filtering the files, we will use the ForEach activity to iterate through each file and check its size. If the file size is equal to or larger than 1KB, we will use the Copy activity to copy the data inside the file to the Azure SQL Database table. Otherwise, we will use the Delete activity to delete the file from the source container.

Testing the Pipeline

Once the pipeline is created, we can test it by executing it under debug mode. This will allow us to verify that all activities are executed successfully and that the data is copied or deleted based on the specified conditions.

After executing the pipeline, we can confirm the success of the data copy operation by connecting to the Azure SQL Database using SSMS and querying the data.

Conclusion

In this article, we have explored how to use iterations and conditions activities in SQL Server to work with different data stores and validate the data stored in these stores. By leveraging these activities, you can perform complex data operations and ensure the integrity of your data.

Stay tuned for more articles on SQL Server and its various features!

Click to rate this post!
[Total: 0 Average: 0]

Let's work together

Send us a message or book free introductory meeting with us using button below.