2016-08-19 90 views
0

我必須根據目標數據庫中的表中的Max(ID),在我的臨時數據庫中重新生成一個表。SSIS中的Reseeding標識列

因此,我創建了一個查詢,它執行SELECT MAX(ID) AS MaxID From Tablename,並進入結果集並將ResultName命名爲maxID。 (一個執行SQL組件)。

然後,我創建了第二個執行SQL組件,並將參數從前一個組件映射到名爲MaxID(參數大小:0,數據類型:十進制)的參數。

對於第二部分的SQL語句是:

DBCC CHECKIDENT (Person, RESEED, ?) 

我收到以下錯誤:

[Execute SQL Task] Error: Executing the query "DBCC CHECKIDENT (Person, RESEED, ?)" failed with the following error: "The type for parameter '@P1' cannot be deduced in this context.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.

任何指導或幫助將是巨大的。

編輯: 我嘗試使用下面的SQL在我執行SQL任務:

DECLARE @Sql VARCHAR(100) = 'DBCC CHECKIDENT (Person, RESEED, ' + CAST(100 AS VARCHAR) + ')' 
EXEC (@Sql) 

但得到一個錯誤:

[Execute SQL Task] Error: Executing the query "DECLARE @Sql VARCHAR(100) = 'DBCC CHECKIDENT (Pers..." failed with the following error: "Parameter name is unrecognized.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.

+0

使用_expression_設置sql值 –

+0

但要小心......有很多原因,目標中的ID不會與第e來源。你應該使用'SET IDENTITY_INSERT OFF'來代替。 –

+0

Thanks @ Nick.McDermaid - 我不確定如何在'執行SQL'任務上使用表達式。我看到有一個表達式屬性 - 但不知道如何從那裏設置SQL命令,並使用先前執行的「Select Max ...」組件的值。 – Craig

回答

-3

着力構建SQL查詢,並執行它動態sql

+0

我剛纔試過了,但得到一個錯誤。我已經修改了這個問題。 – Craig