SSIS: passing sql command as variable to ole db source

百般思念 提交于 2020-01-16 06:08:29

问题


I have created 2 variables in SSIS, namely ProductValue and SQLQuery. The SQLQuery contain the sql statement as below

"SELECT * FROM Products Where ProductID > " + @[user::ProductValue]

When I pass the SQLQuery variable to Ole db source via data access mode = sql command from variable, system return an error messages as below

Error at Data Flow Task [OLE DB Source [1]]: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80040E14. An OLE DB record is available. Source: "Microsoft SQL Server Native Client 10.0" Hresult: 0x80040E14 Description: "Statement(s) could not be prepared.". An OLE DB record is available. Source: "Microsoft SQL Server Native Client 10.0" Hresult: 0x80040E14 Description: "Incorrect syntax near '+'.".


回答1:


You need to have your SQL Query variable set to EvaluateAsExpression.

If you check the value of the SQL Query Variable in the Variables Grid it should say something like:

SELECT * FROM Products Where ProductID > 1

If it doesn't then you have not defined your variable properly. The Value of your SQL Query variable should not contain any quotes or +, only the expression should in this case.




回答2:


In case anyone runs into this thread, you can change the setting when selecting "Show advanced editor" (=right click on the Oledb source) and select "Component Properties" tab and switch "AccessMode" to "SQL Command From Variable".




回答3:


Put the command like this: "SELECT * FROM Products Where ProductID > " + (DT_STR, 10, 1252) @[user::ProductValue] + ""



来源:https://stackoverflow.com/questions/17071451/ssis-passing-sql-command-as-variable-to-ole-db-source

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!