Objective
I decided to combine SSIS and PowerShell 7.0 to create one new ETL SSIS package that transfers CSV files to SQL server using a configuration table, the objective is to create a config table in SQL that contained all the information about an ETL like
1 - Source SQL table
2 - Selected fields
3 - Filters like the t-sql WHERE clause
4 - Tracking mechanism
5 - Destination File Path
6 - Destination File name and extension
7 - etc...
.
Requirements
The powershell script will read CSV files and insert the data into a SQL Server destiantion table, the parameters are as mentioned.
- [String]$srcSQLServerConnectionString = "Server = ABC ; Database = XYZ; Integrated Security = True;"
- [String]$srcSELECTQuery = "SELECT Fields FROM tblXYZ"
- [String]$desFilePath = "<DRIVER>:\...\ETLFolder\FileToBeSFTPed"
- [String]$desFileName = "YYYY-MM-DD HHMMSS FileName"
- [String]$desFileExtension = "csv" OR "txt"
- [String]$desColumnDelimiter = "TAB" # "TAB" "`t" | ; `
At this point the SSIS package will read the config table, start a "Tracking mechanism" (getting the MAX identity field or MAX modified date) then create a final T-SQL string for the PowerShell.
Some of the config table are as mentioned
Source Fields
- [srcTableSchema] nvarchar(20)
- [srcTableName] nvarchar(200)
- [srcFieldList] nvarchar(2000)
- [srcWHEREClause] nvarchar(1000)
- etc...
Destination Fields
- [desFolder] nvarchar(2000)
- [desFileName] nvarchar(50)
- [desFileExtension] nvarchar(50)
- ....
- [srcPreExecute_usp] nvarchar(50)
- [srcPostExecute_usp_Success] nvarchar(50)
- ....
Please note…
- PowerShell script may need to be registered
- The SSIS has an internal logging system
- Three custom SQL stored procedures can be used/set within the configuration table for each ETL , one for PreETL, second PostETLSuccess and Finally PostETLFailure
Do you want the code? Click here (From Google).
I would be fantastic if you could point me in the direction of a good platform.
ReplyDeleteBA Result 2022 - B.A. 1st 2nd 3rd Year Exam Result