openquery 给出不同的结果

发布于 2024-07-30 02:14:02 字数 715 浏览 4 评论 0原文

我有 2 个类似的查询

select * 
from openquery(powerschool, 
                'select * 
                 from TEACHERS 
                 where teachernumber is not null 
                   and schoolid=''1050'' 
                   and teacherloginid is not null  
                 order by teachernumber') 

SELECT * 
from openquery(powerschool, 
              'SELECT NVL(teachernumber,'''') 
               from TEACHERS 
               where teachernumber is not null 
                 and schoolid=''1050'' 
                 and teacherloginid is not null 
               order by teachernumber') 

第一个查询给了我 182 行,而第二个查询给了我 83 行。

查询有什么问题?

I have 2 similar queries

select * 
from openquery(powerschool, 
                'select * 
                 from TEACHERS 
                 where teachernumber is not null 
                   and schoolid=''1050'' 
                   and teacherloginid is not null  
                 order by teachernumber') 

and

SELECT * 
from openquery(powerschool, 
              'SELECT NVL(teachernumber,'''') 
               from TEACHERS 
               where teachernumber is not null 
                 and schoolid=''1050'' 
                 and teacherloginid is not null 
               order by teachernumber') 

The first one is giving me 182 rows while the second one gives me 83.

What's wrong with the queries?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

童话 2024-08-06 02:14:03

只是想法...

  • 同一服务器? 也就是说,链接服务器的目标或凭据不同 o 您正在读取不同的“TEACHERS”表

  • 在链接服务器(而不是本地)上实际运行两个链接 SQL 语句会给您带来什么?

Just thoughts...

  • Same server? That is, linked server is different in target or credentialss o you are reading a different "TEACHERS" table

  • What does running both linked SQL statement actually on the linked server (not locally) give you?

白日梦 2024-08-06 02:14:02

由于 NVL(),第二个查询永远不会为教师表返回 null,因此它可以根据数据返回更多记录。

基本上“and schoolloginid is not null”永远不会被击中,因为你用“”替换了空值

Second query never would return a null for the teachers table because of the NVL() so it could return more records depending on the data.

basically the " and teacherloginid is not null " never gets hit because you replace the nulls with ""

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文