将SSIS参数传递到OPENQUERY

时间:2018-11-28 13:53:43

标签: sql sql-server tsql ssis openedge

请帮助我将SSIS中的参数传递到“ OPENQUERY”中,以测试我正在使用以下脚本但出现错误的查询:

脚本:

DECLARE @TSQL varchar(8000), @Date varchar(11)
SELECT  @Date = '28 Nov 2018'
SELECT  @TSQL = 'SELECT * FROM OPENQUERY([TEST], ''SELECT * FROM PUB.TEST
WHERE Test_Date >= ''''' + @Date + ''''''')'
EXEC (@TSQL)

错误:

OLE DB provider "MSDASQL" for linked server "TEST" returned message "[DataDirect][ODBC Progress OpenEdge Wire Protocol driver][OPENEDGE]Invalid date string (7497)".
Msg 7321, Level 16, State 2, Line 4
An error occurred while preparing the query "SELECT * FROM PUB.TEST 
WHERE Test_Date >= '28 Nov 2018'" for execution against OLE DB provider "MSDASQL" for linked server "TEST". 

SSIS OLE DB源中的脚本应如下所示:

DECLARE @TSQL varchar(8000), @Date varchar(11)
SELECT  @Date = ?
SELECT  @TSQL = 'SELECT * FROM OPENQUERY([TEST], ''SELECT * FROM PUB.TEST
WHERE Test_Date >= ''''' + @Date + ''''''')'
EXEC (@TSQL)

1 个答案:

答案 0 :(得分:0)

将脚本修改为以下内容,日期格式存在问题

DECLARE @TSQL varchar(8000), @Date varchar(11)
SELECT  @Date = '28-Nov-2018'
SELECT  @TSQL = 'SELECT * FROM OPENQUERY([TEST], ''SELECT * FROM PUB.TEST
WHERE Test_Date >= ''''' + @Date + ''''''')'
EXEC (@TSQL)