本地查询与 openquery 未返回相同结果
我有一个链接到 SQL Server 数据库的 Oracle 数据库。
每当我在 Oracle 中执行特定查询时,我都会得到预期的数据。
我选择的字段是
SELECT
J.JOBNUMBER AS JOBNUMBER,
J.OPENDATE AS OPENDATE,
S.SERVICEREPORTNUMBER AS SERVICEREPORTNUMBER,
F.SSO AS SSO,
S.DATEOFVISIT AS DATEOFVISIT,
CASE WHEN J.SOURCE='MUST' THEN SRVCD.DACRENR ELSE W.DEBRIEFDATE END as "DEBRIEFDATE",
J.CLOSEDDATE AS CLOSEDDATE,
INITCAP(HR.COUNTRY_NAME) as "COUNTRY",
F.NAME AS NAME,
SY.MODALITY AS MODALITY,
HR.MANAGER_SSOID AS MANAGER_SSOID,
HR.MANAGER_NAME AS MANAGER_NAME
如果我使用 openquery 执行相同的查询,我会在对应于的列上得到空值
CASE WHEN J.SOURCE='MUST' THEN SRVCD.DACRENR ELSE W.DEBRIEFDATE END as "DEBRIEFDATE"
在这种情况下,该列保存日期,并且显示与 SRVCD.DACRENR 对应的字段以及 W.DEBRIEFDATE 日期不是。
我不知道为什么我在 Oracle 中正确地看到了这些值,但在 openquery 结果中却看不到这些值。我尝试使用 TO_CHAR 和 TO_DATE 更改值,并且我在 Oracle 中看到这些值但在 SQL Server 中看不到这些值。
I have an Oracle database linked to a SQL Server database.
Whenever I perform a specific query in Oracle I get expected data.
The fields I'm selecting are
SELECT
J.JOBNUMBER AS JOBNUMBER,
J.OPENDATE AS OPENDATE,
S.SERVICEREPORTNUMBER AS SERVICEREPORTNUMBER,
F.SSO AS SSO,
S.DATEOFVISIT AS DATEOFVISIT,
CASE WHEN J.SOURCE='MUST' THEN SRVCD.DACRENR ELSE W.DEBRIEFDATE END as "DEBRIEFDATE",
J.CLOSEDDATE AS CLOSEDDATE,
INITCAP(HR.COUNTRY_NAME) as "COUNTRY",
F.NAME AS NAME,
SY.MODALITY AS MODALITY,
HR.MANAGER_SSOID AS MANAGER_SSOID,
HR.MANAGER_NAME AS MANAGER_NAME
If I do the same query with openquery I get null values on the column which corresponds to
CASE WHEN J.SOURCE='MUST' THEN SRVCD.DACRENR ELSE W.DEBRIEFDATE END as "DEBRIEFDATE"
In this case the column holds dates and the ones that correspond to SRVCD.DACRENR are being shown and the W.DEBRIEFDATE dates are not.
I don't know why I'm seeing those values correctly in Oracle but not in the openquery result. I tried changing the values with TO_CHAR and TO_DATE and all scecnarios I see the values in Oracle but not in SQL Server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试将日期转换为 varchar 以便它与相同的数据类型匹配吗?
或者发布一些示例数据
Could you try a convert to varchar on your date so it match the same datatype?
Or post some sample data
不确定如何在 OPENQUERY 中声明变量。有一种直接方式,您不使用任何变量来存储查询以供以后执行,还有一种间接方式,与直接方式相反。大多数时候,间接方式是获得预期结果的最佳方式。
首先,您需要声明一些变量并使用 EXEC() 函数执行它。让我们看看它是如何完成的。
要记住的要点:
希望这有帮助。
Not sure how you declare your variables in OPENQUERY. There is one direct way where you don't use any variables to store the query for latter execution, and indirect way which is the opposite way of direct way. Most of the times, indirect way is the best way in order to get the desired results.
First you will need to declare some variables and execute it using
EXEC()
function. Let's see how it is done.Points to remember:
Hope this helps.