我正在尝试将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)
我想要动态传递Key值,这可以由?设置,但是我无法这样做。有没有办法实现它?
提前致谢。
答案 0 :(得分:0)
这是我在数据流中工作的脚本组件。只读变量valVariable
和MyKey
。 ReadWrite变量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