SSIS包如何成功执行foreach或for循环以自动增加字段插入的值?

时间:2015-07-03 01:37:36

标签: sql-server for-loop foreach ssis

首先,我在SSIS中从未尝试过类似的东西,而且我对SSIS包的开发还很陌生。

我需要在我的包中构建一个组件,该组件将运行一个数据表(比如80行),并将标题为DisplayOrder的字段设置为自动递增的数字。问题是其中一条记录必须设置为0,然后其余的记录设置为自动递增的数字。

关于代码,我甚至不确定要附加到此问题的代码甚至是什么屏幕截图。

1 个答案:

答案 0 :(得分:0)

我终于想通了,不需要循环。

  1. 创建SQL任务以清除链接的表。
  2. 使用的脚本

    DELETE FROM [Currency].[ExchangeRates]
    
    1. 创建SQL任务以清除主表。
    2. 使用的脚本

      DELETE FROM [Currency].[CurrencyList]
      
      1. 将值加载到主表中。
      2. 已使用的操作

        • 从XML Source
        • 加载值
        • 将值转储到[ExchangeRates]表

          1. 创建SQL任务以将值从主表加载到链接表。

        使用的脚本

        INSERT INTO [Currency].[CurrencyList] (CurrencyCode, CurrencyName, ExchangeRateID, DisplayOrder) SELECT [er].[TargetCurrency] AS [CurrencyCode], [er].[TargetName] AS [CurrencyName], [er].[ID] AS [ExchangeRateID], ROW_NUMBER() OVER (ORDER BY [ER].[TargetName]) AS [DisplayOrder] FROM [Currency].[ExchangeRates] AS [er] ORDER BY [CurrencyName]
        
        1. 创建一个SQL任务以将新记录加载到主表以用作DisplayOrder 0。
        2. 使用的脚本

          INSERT INTO [Currency].[ExchangeRates] ([Title], [Link], [Description], [PubDate], [BaseCurrency], [TargetCurrency], [TargetName], [ExchangeRate]) VALUES ('1 USD = 1 USD','http://www.floatrates.com/usd/usd/','1 U.S. Dollar = 1 U.S. Dollar',(SELECT TOP 1 [PubDate] FROM [Currency].[ExchangeRates]),'USD','USD','United States Dollar','1')
          
          1. 创建一个SQL任务以引用主表中新创建的记录。
          2. 使用的脚本

            INSERT INTO [Currency].[CurrencyList] (CurrencyCode, CurrencyName, ExchangeRateID, DisplayOrder) SELECT [er].[TargetCurrency] AS [CurrencyCode], [er].[TargetName] AS [CurrencyName], [er].[ID] AS [ExchangeRateID], 0 AS [DisplayOrder] FROM [Currency].[ExchangeRates] AS [er] WHERE [er].[TargetCurrency] = 'USD'