![](/img/trans.png)
[英]Migrating Data from a SQL Server Encrypted Table to SQL Azure using Azure Data Factory Copy data
[英]How to load data from excel to SQL DB using Azure Data Factory
有很多方法可以做到這一點,但我將向您展示我認為最簡單的方法。
請參閱下面的屏幕截圖和評論以進行演練(在不使用 Azure 函數或其他東西的情況下,目前無法在 ADF 中以本機方式獲取工作表名稱,但我已盡可能多地覆蓋。如果 excel 的名稱相同作為可以替代的工作表,這是一個選項,我在這個例子中做了什么):整體管道視圖 第一步截斷舞台表以確保在加載之前它是空的
第 2 步加載帶有文件輸入的 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
如果這對您有用,請接受作為答案,如果您有任何其他意見或問題,請告訴我。 謝謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.