I need to create a database using a CSV file with SSIS. The CSV file includes four columns:
I need to use the information of that table to populate the three tables I created in SQL below.
I have realized that what I need is to use one column of the Employee Table, EmployeeNumber
, and Group Table, GroupID
, to populate the EmployeeGroup table. For that, I thought that a Join Merge table is what I needed, but I created the Data Flow Task in SSIS, and the results are the same, no data displayed.
The middle table is the one used to relate the other tables.
I created the package in SSIS and the Employee and Group Tables are populated, but the EmployeeGroup table is not. EmployeeGroup will only show the EmployeeNumber and Group ID columns with no data.
I am new using SSIS, and I really do not know what else to do. I will really appreciate your help.
Overview
1st Solution - SSIS
Using 3 Data Flow Tasks
This can be done using only 2 Data Flow Task, but according to what the OP mentioned in the question
I am new using SSIS, and I really do not know what else to do
, i will provide easiest solution which is 3 DataFlow Task to avoid using more components likeMultiCast
.Solution Overview
Because you want to build a relational database and extract relations from the csv, you have to read the csv 3 times -consider it as 3 seperated files -.
First you have to import Employees and Groups Data, Then you have to import the relation table between them.
Each Import step can be done in a seperate Data Flow Task
Detailed Solution
First Data Flow Task
SynchronousInputID Property
toNone
And add an output columnOutGroupname
with typeDT_STR
In the Script section write the following Code:
On the OLEDB Destination map
OutGroupName
toGroupName
ColumnSecond Data Flow Task : Import Employees Data
Groupname
Column : with a single difference that is you have to choose theEmployeeID
,Employee Name
,LoginName
columns as Input in the Script Component and Use theID
Column instead ofGroupname
column in the comparaisonThird Data Flow Task : Import Employees_Group Data
In The LookUp Transformation Component select
Groups
Table as a Lookup tableMap
GroupName
Columns and GetGroup ID
as outputChoose
Ignore Failure
in the Error Output ConfigurationIn Oledb Destination map columns as following
Note:
GroupID
must be an Identity (set it in sql server)Using 2 Data Flow Tasks
You have to do the same steps as the 3 Data Flow Tasks solution, but instead of adding 2 Data Flow Tasks to
Group
andEmployee
, just add one Data Flow Task, and after theFlat File Source
add aMultiCast
component to duplicate the Flow. Then for the first flow use the sameScript Component
andOLEDB Destination
used in theEmployee
Data Flow Task, and for the second flow use theScript Component
andOLEDB Destination
related toGroup
.2nd Solution - Using TSQL
There are many method to import Flat file to SQL via T-SQL commands
OPENROWSET with Microsoft ACE OLEDB provider
Assuming that the installed version of Microsoft ACE OLEDB is
Microsoft.ACE.OLEDB.12.0
and that the csv file location isC:\abc.csv
First Import data into Employee and Group Table
Import the Employee_Group Data
OPENROWSET with Microsoft Text Driver
First Import data into Employee and Group Table
Import the Employee_Group Data
Note: You can Import Data to a staging table, then query this table, to avoid connecting many times to the csv File
Solutions Using PowerShell
There are many method to import csv files to SQL server, you can check the following links for additional informations.
References
Since you already know how to import the csv and extract two tables (Employee and Group), I suggest you just populate EmployeeGroup in the same way. And stop using a group_id. If you do that, you'll get sql statements like:
Most likely, you'll have similar statements already working for Employee and Group. In this option you can make it work in the same way, without using a Join Merge. It's a usefull option, but clearly somewhere in that component something goes wrong.
I think the easiest solution would be to import the csv to a flat staging table and then use some
insert into...select
statements to populate the target tables. Assuming you know how to import to a flat table, the rest is quite simple:You can see a live demo on rextester.