我有一个SSIS作业,用于将平面文件加载到数据库中。我将文件名加载到SQL数据库中的一列中。在第一步中,我检查文件名是否已经存在。如果这样做,文件将被删除。如果没有,它将被处理和加载。原始文件是.dat。问题是,由于另一个进程,加载的文件被重命名为名称末尾附加的"_flat.txt",与原始文件不匹配。
"YC_HSO_PA_0_Test_1.dat">
"YC_HSO_PA_0_Test_1_flat.txt">
存储文件原始名称的变量是"User::FileNameCheck"。我核对的表格是TOC。PA_STAGE。我用来检查的表达式是:
"DECLARE @FileName VARCHAR (100)
SET @FileName = '"+ @[User::FileNameCheck] +"'
IF EXISTS (SELECT 1
FROM [TOC].[PA_STAGE]
WHERE FileName = @FileName)
BEGIN
SELECT 0 AS LoadStatusFlag
END
ELSE
BEGIN
SELECT 1 AS LoadStatusFlag
END"
我试过这个:
"DECLARE @FileName VARCHAR (100)
SET @FileName = REPLACE(REPLACE(@[User::FileNameCheck],'.txt',''),'.dat','') +'_flat.txt'
IF EXISTS (SELECT 1
FROM [TOC].[PA_STAGE]
WHERE FileName = @FileName)
BEGIN
SELECT 0 AS LoadStatusFlag
END
ELSE
BEGIN
SELECT 1 AS LoadStatusFlag
END"
但是得到一个错误:SET@FileName=R…"失败,返回以下错误:"必须声明标量变量"@"。".
我可以使用"LIKE"语句来查找要匹配的文件名吗。或者以某种方式将_flat.txt附加到变量中?
看起来您的代码没有扩展@[User::FileNameCheck]的值。尝试:
"DECLARE @FileName VARCHAR (100)
SET @FileName = REPLACE(REPLACE('" + @[User::FileNameCheck] + "','.txt',''),'.dat','') +'_flat.txt'
IF EXISTS (SELECT 1
FROM [TOC].[PA_STAGE]
WHERE FileName = @FileName)
BEGIN
SELECT 0 AS LoadStatusFlag
END
ELSE
BEGIN
SELECT 1 AS LoadStatusFlag
END"