在SSIS中,如何为变量赋值?

时间:2013-04-01 09:39:35

标签: ssis

我有SQL查询,提到过@Result。 现在我想将@Result的值赋给DFT的Execute SQL task中的声明变量。你能帮帮我吗?

这是查询:

DECLARE @Result SMALLINT 
DECLARE @VALUE  SMALLINT

BEGIN 
SET @VALUE = (SELECT Value 
              from dbo.LDMStockIntegrityCheck 
              where InterfaceName =  'I0180'
              and FileName = 'PIZ.ED.NBFS001.PICSHT.DATA.LDM')
SET @Result = 0;

IF (@VALUE = 1)
BEGIN 
Select @Result = count(*) from dbo.LDMIntegrityErrorLog 
where InterfaceName = 'I0180' and FileName = 'PIZ.ED.NBFS001.PICSHT.DATA.LDM'
and  CONVERT(VARCHAR(10), DateTime, 120) = CONVERT(VARCHAR(10), getdate(), 120);
END 

END

1 个答案:

答案 0 :(得分:1)

如果您想Output来自查询count count(*) from dbo.LDMIntegrityErrorLog的值,那么我看不到变量@Result的重要性

DECLARE @VALUE  SMALLINT

BEGIN 
SET @VALUE = (SELECT Value 
              from dbo.LDMStockIntegrityCheck 
              where InterfaceName =  'I0180'
              and FileName = 'PIZ.ED.NBFS001.PICSHT.DATA.LDM')

IF (@VALUE = 1)
BEGIN 
Select count(*) as Result from dbo.LDMIntegrityErrorLog 
where InterfaceName = 'I0180' and FileName = 'PIZ.ED.NBFS001.PICSHT.DATA.LDM'
and  CONVERT(VARCHAR(10), DateTime, 120) = CONVERT(VARCHAR(10), getdate(), 120);
END 
ELSE
SELECT NULL AS Result
END

删除查询中的变量@Result

现在创建数据类型为TaskResult的变量int。将此变量映射到上述查询中的result

enter image description here