在sql select语句以及where子句SSIS中传递参数

在sql select语句以及where子句SSIS中传递参数,sql,dynamic,ssis,Sql,Dynamic,Ssis,我试图将SQL命令作为SQL数据源中的变量获取 "SELECT " + (DT_WSTR, 25) @[User::valVariable] + " As Value from dbo.MyTable WHERE (Key= " + (DT_WSTR, 25)@[User::MyKey] + ")" 这是一个变量表达式,为此生成的值为: SELECT 1 As Value from dbo.MyTable WHERE (Key = 0) 我希望动态传递键值,该键值可以由?

我试图将SQL命令作为SQL数据源中的变量获取

"SELECT   " + (DT_WSTR, 25) @[User::valVariable] + " As Value from dbo.MyTable WHERE        (Key= " +  (DT_WSTR, 25)@[User::MyKey] + ")"
这是一个变量表达式,为此生成的值为:

SELECT 1 As Value from dbo.MyTable WHERE (Key = 0)
我希望动态传递键值,该键值可以由?设置,但我无法这样做。有什么办法可以实现吗


提前感谢。

这是我在数据流中使用的脚本组件。只读变量
valVariable
MyKey
。读写变量
MySelect

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper
Public Class ScriptMain
    Inherits UserComponent
    Private StrTemp As String
    Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
        If UCase(Row.Current) = "Y" Then
            StrTemp = "Select " & CStr(Me.Variables.MyVariable) & " as Value  from dbo.Table Where (Key =" & CStr(Me.Variables.MyKey) & ")"
        End If
    End Sub
    Public Overrides Sub PostExecute()
        Me.Variables.MySelect = StrTemp
        MsgBox("Select statement: " & Me.Variables.MySelect)
    End Sub
End Class

你是写文章还是帮忙?我看过了。这些只是帮助您创建变量。我想在变量中使用变量:(您可以设置一个脚本,其中包含两个只读变量(valVariable和MyKey)和一个读/写变量mySelect(String)。在脚本中执行select语句连接并输出mySelect。