有很多方法可以做到这一点,但我会告诉你我认为最简单的方法。
- 在 Azure 数据工厂中设置复制数据活动以复制数据
从 excel 到 Azure SQLDB 临时表。
- 在 Azure SQLDB 中创建一个存储过程,该过程将从暂存表插入到最终输出表中
- 将存储过程活动连接到 ADF 中的复制数据活动,以引用您刚刚在数据库中创建的过程,这样 ADF 将在加载登台表后立即运行存储过程。
- 您可以在加载最终输出表之后或在 ADF 中的复制活动之前使用命令/过程来清除暂存表。
请参阅下面的屏幕截图和 cmets 进行演练(在不使用 Azure 函数或其他东西的情况下,目前无法在 ADF 中以本机方式获取工作表名称,但我已尽我所能。如果 excel 是命名与可以使用的工作表相同,这是一个选项,我在这个例子中做了什么):
整体管道视图
第一步截断 Stage Table 以确保在加载之前它是空的
第二步加载带有文件输入的 Stage 表
最后一步是运行存储过程
这是我在下面制作的存储过程的代码,以及 ADF 存储过程活动的屏幕截图:
create procedure stag.ttt_test (@ExcelFileName varchar(100))
as
DECLARE @ClassStartRow int
select @ClassStartRow = max(RowId)
from (
select
case when Details = '2.Class' then ROW_NUMBER() over (order by %%physloc%%) else 0 end as RowId
from Stag.ttt_test_stage
) as sub
;
INSERT INTO Stag.ttt_test_final
select
Case
when January is NOT NULL then DATEADD(day, -1, cast('2/1/' + cast(YEAR(getdate()) as varchar(4)) as date))
when February is NOT NULL then DATEADD(day, -1, cast('3/1/' + cast(YEAR(getdate()) as varchar(4)) as date))
when March is NOT NULL then DATEADD(day, -1, cast('4/1/' + cast(YEAR(getdate()) as varchar(4)) as date))
when April is NOT NULL then DATEADD(day, -1, cast('5/1/' + cast(YEAR(getdate()) as varchar(4)) as date))
when May is NOT NULL then DATEADD(day, -1, cast('6/1/' + cast(YEAR(getdate()) as varchar(4)) as date))
when June is NOT NULL then DATEADD(day, -1, cast('7/1/' + cast(YEAR(getdate()) as varchar(4)) as date))
when July is NOT NULL then DATEADD(day, -1, cast('8/1/' + cast(YEAR(getdate()) as varchar(4)) as date))
when August is NOT NULL then DATEADD(day, -1, cast('9/1/' + cast(YEAR(getdate()) as varchar(4)) as date))
when September is NOT NULL then DATEADD(day, -1, cast('10/1/' + cast(YEAR(getdate()) as varchar(4)) as date))
when October is NOT NULL then DATEADD(day, -1, cast('11/1/' + cast(YEAR(getdate()) as varchar(4)) as date))
when November is NOT NULL then DATEADD(day, -1, cast('12/1/' + cast(YEAR(getdate()) as varchar(4)) as date))
when December is NOT NULL then DATEADD(day, -1, cast('1/1/' + cast(YEAR(getdate()) + 1 as varchar(4)) as date))
end as [Date],
'name' as Category,
Details as [Type],
Coalesce(January, February, March, April, May, June, July, August, September, October, November, December) as [value],
@ExcelFileName as SheetName
from (
select
ROW_NUMBER() over (order by %%physloc%%) as RowId,
st.*
from Stag.ttt_test_stage as st
) as sub
where RowId > 1
and RowId < @ClassStartRow
;
INSERT INTO stag.ttt_test_final
select
Case
when January is NOT NULL then DATEADD(day, -1, cast('2/1/' + cast(YEAR(getdate()) as varchar(4)) as date))
when February is NOT NULL then DATEADD(day, -1, cast('3/1/' + cast(YEAR(getdate()) as varchar(4)) as date))
when March is NOT NULL then DATEADD(day, -1, cast('4/1/' + cast(YEAR(getdate()) as varchar(4)) as date))
when April is NOT NULL then DATEADD(day, -1, cast('5/1/' + cast(YEAR(getdate()) as varchar(4)) as date))
when May is NOT NULL then DATEADD(day, -1, cast('6/1/' + cast(YEAR(getdate()) as varchar(4)) as date))
when June is NOT NULL then DATEADD(day, -1, cast('7/1/' + cast(YEAR(getdate()) as varchar(4)) as date))
when July is NOT NULL then DATEADD(day, -1, cast('8/1/' + cast(YEAR(getdate()) as varchar(4)) as date))
when August is NOT NULL then DATEADD(day, -1, cast('9/1/' + cast(YEAR(getdate()) as varchar(4)) as date))
when September is NOT NULL then DATEADD(day, -1, cast('10/1/' + cast(YEAR(getdate()) as varchar(4)) as date))
when October is NOT NULL then DATEADD(day, -1, cast('11/1/' + cast(YEAR(getdate()) as varchar(4)) as date))
when November is NOT NULL then DATEADD(day, -1, cast('12/1/' + cast(YEAR(getdate()) as varchar(4)) as date))
when December is NOT NULL then DATEADD(day, -1, cast('1/1/' + cast(YEAR(getdate()) + 1 as varchar(4)) as date))
end as [Date],
'class' as Category,
Details as [Type],
Coalesce(January, February, March, April, May, June, July, August, September, October, November, December) as [value],
@ExcelFileName as SheetName
from (
select
ROW_NUMBER() over (order by %%physloc%%) as RowId,
st.*
from Stag.ttt_test_stage as st
) as sub
where RowId > @ClassStartRow
如果这对您有用,请接受作为答案,如果您有任何其他 cmets 或问题,请告诉我。谢谢