从文件夹插入文件名,并从文件名检索日期-SSIS

问题描述 投票:0回答:1

IS

File Name
Product _Resale_01-11-2020 0725_20200113090542634.CSV
Product _Resale_01-11-2020 0725_20200113090542633.CSV
Product _Resale_01-11-2020 0725_20200113090542637.CSV
Product _Resale_01-11-2020 0725_20200113090542636.CSV
Product _Resale_01-11-2020 0725_20200113090542635.CSV
HealthTrust_Account_01-12-2020 1020_20200112090016408.CSV
Medical_numbers_01-13-2020 0100_20200112110113509.CSV
New_Sale_Product_Manufacturer Sercices_01-12-2020 0745_20200111060038248.CSV
New_Sale_Product_Manufacturer Sercices_01-12-2020 0745_20200111060038264.CSV
New_Sale_Product_Manufacturer Sercices_01-12-2020 0745_20200111060038279.CSV
Product _Resale_01-11-2020 0725_20200113090542416.CSV
Product _Resale_01-11-2020 0725_20200113090542431.CSV
Product _Resale_01-11-2020 0725_20200113090542447.CSV
Product _Resale_01-11-2020 0725_20200113090542463.CSV
Product _Resale_01-11-2020 0725_20200113090542636.CSV
Product _Resale_01-11-2020 0725_20200113090542631.CSV
Product _Resale_01-11-2020 0725_20200113090542634.CSV
Product _Resale_01-11-2020 0725_20200113090542632.CSV
Product _Resale_01-11-2020 0725_20200113090542633.CSV
Product _Resale_01-11-2020 0725_20200113090542635 .CSV

预期

enter image description here

问题:带有文件名的数据到我的本地文件夹中,我想将所有这些文件名插入数据库SQL Server并从中检索日期

sql-server ssis
1个回答
0
投票

在SSIS中,您可以通过Foreach Loop ContainerExecute SQL Task完成此操作。

1。将Foreach循环容器指向目标文件夹。

enter image description here

2。映射到变量

enter image description here

3。使用执行SQL任务将数据INSERT放入SQL Server的表中。

4。查询数据。

CREATE TABLE #MyTable (MyFileName VARCHAR(255))
INSERT INTO #MyTable VALUES
('Product _Resale_01-11-2020 0725_20200113090542634.CSV')
, ('Medical_numbers_01-13-2020 0100_20200112110113509.CSV')
, ('New_Sale_Product_Manufacturer Sercices_01-12-2020 0745_20200111060038279.CSV')

SELECT
    MyFileName
    , SUBSTRING(MyFileName, CHARINDEX('-', MyFileName) - 2, 10)
FROM #MyTable
© www.soinside.com 2019 - 2024. All rights reserved.