Search code examples
sql-servercsvssisetlflat-file

Split rows based on defined values for column from csv file


I have data as below into csv file and I want to pick certain data from it using ssis technology

I need only those rows from ID column 23145, 876459, 1022

+--------+------+-----------+
|   ID   | Name |  Address  |
+--------+------+-----------+
|   1022 | XYZ  | Texas     |
|   2347 | zzz  | Virginia  |
|  23145 | TTT  | New York  |
|  45673 | ZWT  | Maryland  |
|   9870 | RET  | Florida   |
| 876459 | TERW | Oklahoma  |
| 980456 | YUIE | Georgia   |
+--------+------+-----------+

Result expected

+------+----------+
| Name | Address  |
+------+----------+
| TTT  | New York |
| TERW | Oklahoma |
| XYZ  | Texas    |
+------+----------+

Solution

  • You can simply use a conditional split component within a data flow task to filter rows based on ID using a similar expression:

    [ID] == 23145 || [ID] == 876459 || [ID] == 1022
    

    For more information about SSIS conditional split you can refer to the following article:


    Update 1 - Filtering using two columns

    Try to use && (and) and || (or) operators within your expression:

    ([Name] == "TTT" && [Address] == "New York") || ([Name] == "TERW" && [Address] == "Oklahoma") || ([Name] == "XYZ" && [Address] == "Texas")