我一直在努力将以下t sql任务转换为自动ssis包。 我尝试使用for loop conntainer实现,但在创建循环逻辑时,我正在坚持下去。我真的很感激有人可以用逻辑来帮助我
这是t-sql代码
-- SCRIPT TO BULK IMPORT MATERNAL HLA & INSERT CORD NIMA
IF OBJECT_ID('tempdb..#maternal_hla_from_solar') IS NOT NULL
BEGIN
drop table #maternal_hla_from_solar
END
CREATE TABLE #maternal_hla_from_solar(
[donor_id] [int] NOT NULL,
[antigen_id] [int] NOT NULL
)
-- bulk upload maternal HLA from file
BULK
INSERT #maternal_hla_from_solar
FROM 'C:\Users\zabeenp\Documents\SQL\populate_db\data\20111212_maternal_hla.txt'
WITH
(
FIRSTROW = 2,
MAXERRORS = 0,
FIELDTERMINATOR = '\t',
ROWTERMINATOR = '\n'
)
-- declare variables
DECLARE @donor_id int
DECLARE @maternal_hla varchar(5000)
DECLARE @definitive_type_date date = GETDATE()
DECLARE @modified_on datetime2(7) = GETDATE()
-- Cursor to process each row from #maternal_hla_from_solar
DECLARE c_insertCordNima CURSOR FAST_FORWARD
FOR select DISTINCT donor_id from #maternal_hla_from_solar -- important to use DISTINCT here
OPEN c_insertCordNima
FETCH NEXT FROM c_insertCordNima INTO @donor_id
WHILE @@FETCH_STATUS = 0
BEGIN
SET @maternal_hla = '' -- important to wipe string each time
-- concatenare maternal antigen_ids into one string
SELECT @maternal_hla = COALESCE(@maternal_hla + ',', '') + CONVERT(VARCHAR(10),antigen_id)
FROM #maternal_hla_from_solar
where donor_id = @donor_id
-- remove first comma
SET @maternal_hla = (select right(@maternal_hla,len(@maternal_hla)-1))
-- exec insertCordNIMA SP
EXECUTE insertCordNIMA
@donor_id
,@maternal_hla
,@definitive_type_date
,@modified_on
FETCH NEXT FROM c_insertCordNima INTO @donor_id
END
CLOSE c_insertCordNima
DEALLOCATE c_insertCordNima