I am loading many .csv files into a SQL Server table using SSIS (Visual Studio 2017).
I am using For Each Loop Container. I have two user variables - FileName (string) and RowCnt (int)
I have developed an audit table (dbo.FEfiles) to track each file loaded along with the number of records in each file.
Audit table has two columns:
1) FileName(varchar(20)
2) RowCount(int)
After the setting up of the Data Flow Task inside the For Each Loop Container, I have an Execute SQL Task that connects to my audit table.
In this Execute SQL Task, in the Expression tab, under the SQLStatementSource, I have the following expression to get the file namealone:
"INSERT INTO dbo.FEfiles (FileName) SELECT '" + @[User::Filename] + "' "
This parses correctly when I evaluate the expression, I get:
INSERT INTO dbo.FEfiles (FileName) SELECT 'filename.CSV'
Now, how do I add the variable for the RowCnt, which has integer data type ?
I tried many options such as the one below:
"INSERT INTO dbo.FEfiles (FileName,RowCount) SELECT '" + @[User::Filename] + "', + (DT_WSTR, 12) @[User::RowCnt] "
When I evaluate the expression, I get the following:
INSERT INTO dbo.FEfiles (FileName,RowCount) SELECT 'filename.CSV',+ (DT_WSTR, 12) @[User::RowCnt]
I need to get INSERT INTO dbo.FEfiles (FileName,RowCount) SELECT 'filename.CSV',0 instead
Can you kindly help me in getting the right expression ?
I even watched this video, but not able to figure out:
https://www.youtube.com/watch?v=Um7tDy9jZRs