我无法成功地将带有 openquery 的代码运行到 oracle 服务器。
请不要考虑字段名称/数据类型,因为我只需要展示整个过程的一部分。它很长。我相信问题出在引号等...
程序编译好了。每次我执行该过程时,都会发生错误:
Quote: Msg 105, Level 15, State 1, Line 53 字符串'SELECT TO_NUMBER(XYZ_1) XYZ_1, XYZ_2,
cast (''''0'''' as number(5)) as B1, cast(''''1753-01-01'''' as date) NULL_DATE
我迷路了——我到底应该把那些缺失的引号放在哪里?
代码:
代码:[全选] [显示/隐藏] CREATE TABLE #tmpXYZ Header ( [XYZ_1] [int] PRIMARY KEY, [XYZ_2] varchar, [XYZ_3] varchar, -- 更多字段
[XYZ_N] varchar )
声明 @sqlInv nvarchar(3000) 设置 @sqlInv =
'insert into #tmpXYZ Header (
[XYZ_1],
[XYZ_2],
[XYZ_3],
-- more fields
[XYZ_N]
)
select
* FROM OPENQUERY(XYZ_ORACLE,
''SELECT TO_NUMBER(XYZ_1) XYZ_1,
XYZ_2,
cast (''''0'''' as number(5)) as B1,
cast(''''1753-01-01'''' as date) NULL_DATE,
-- more fields
cast ('''' '''' as varchar(20)) as A19
from XYZ.V_HEADER
where
(DATE >= ''''TO_DATE(''''' + @startDate + ''''', ''''YYYYMMDD'''')'''' AND
DATE <= ''''TO_DATE(''''' + @endDate + ''''', ''''YYYYMMDD'''')'''' AND
QWE = ''''0'''' AND
ABC = ''''13'''' ) '' )
'
exec sp_executesql @sqlInv