到目前爲止我無法使用Execute SQL任務。現在我從一個腳本任務調用存儲過程並分配給一個變量,直到我得到一個更好的解決方案。
腳本任務
Public Sub Main()
Dim tableName As String = Dts.Variables("User::CurrentTable").Value.ToString()
Dim sourceConnection As SqlConnection
Dim destinationConnection As SqlConnection
Try
Dim cmSource As ConnectionManager
cmSource = Dts.Connections("ADOSourceConnection")
sourceConnection = DirectCast(cmSource.AcquireConnection(Dts.Transaction), System.Data.SqlClient.SqlConnection)
Dim cmDestination As ConnectionManager
cmDestination = Dts.Connections("ADOACIConnection")
destinationConnection = DirectCast(cmDestination.AcquireConnection(Dts.Transaction), System.Data.SqlClient.SqlConnection)
Using destinationConnection
Dim cmd As New SqlCommand()
cmd.Connection = destinationConnection
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "uspGetIncompleteMoveFromArchival"
cmd.Parameters.AddWithValue("@TableName", tableName)
Dim result As String = Convert.ToString(cmd.ExecuteScalar())
Dts.Variables("User::IncompleteMoveXML").Value = result
'Release Connection'
cmSource.ReleaseConnection(sourceConnection)
cmDestination.ReleaseConnection(destinationConnection)
'Success'
Dts.TaskResult = Dts.Results.Success
End Using
Catch ex As Exception
Dim exceptionVariable As Microsoft.SqlServer.Dts.Runtime.Variables = Nothing
Dts.VariableDispenser.LockOneForWrite("User::ScriptException", exceptionVariable)
exceptionVariable("User::ScriptException").Value = ex.Message
exceptionVariable.Unlock()
Dts.Events.FireError(-1, "Task Name", ex.Message, String.Empty, 0)
Dts.TaskResult = Dts.Results.Failure
End Try
End Sub
存儲過程的僞代碼
DECLARE @Result XML
SELECT @Result =
(
SELECT
'SKULocationsSnapShot' AS '@tableName',
(
SELECT CONVERT(VARCHAR(20), SnapShotID) AS SnapShotID,
CONVERT(VARCHAR(20), LocationID) AS LocationID
FROM dbo.SKULocationsSnapShot CurrentTable (NOLOCK)
WHERE IsMoveComplete = 'N'
FOR XML PATH('CurrentRow'), TYPE
)
FOR XML PATH('root')
)
SELECT CAST(
@Result
AS VARCHAR(MAX)
) AS IncompleteMoveXML
我不認爲SSIS可以隱式轉換的對象變量爲varchar。您能否將第一個過程中的XML存儲在字符串變量中而不是對象中? –