SQL 2000 到 SQL 2008

发布于 2024-11-03 01:13:25 字数 520 浏览 1 评论 0原文

我在 SQL 2000 DB 中有一个查询,需要将其迁移到 SQL 2008 DB。它在 SQL2000 中运行良好,我不需要将其修改为 SQL2008。下面是SQL2000中的查询。请指导我如何在 ON 子句中重载 *==* 子句。

SELECT tblacc. *
FROM   tblacc,
       tblst,
       tblreceipt,
       tblrtemp,
       tblitem
WHERE  tblacc.rkey = tblreceipt.rkey
       AND tblacc.stkey = tblst.stkey
       AND tblacc.stkey *= tblrtemp.stkey
       AND tblacc.stkey *= tblitem.stkey
       AND tblacc.itkey *= tblitem.itkey
       AND tblrtemp.rkey =* tblreceipt.rkey 

I have a query in SQL 2000 DB and I need to migrate it to SQL 2008 DB. It works fine in SQL2000 and I j’t need to revamp it into SQL2008. Below is the query in SQL2000. Please guide me how can we overload *= , =* clause in ON clause.

SELECT tblacc. *
FROM   tblacc,
       tblst,
       tblreceipt,
       tblrtemp,
       tblitem
WHERE  tblacc.rkey = tblreceipt.rkey
       AND tblacc.stkey = tblst.stkey
       AND tblacc.stkey *= tblrtemp.stkey
       AND tblacc.stkey *= tblitem.stkey
       AND tblacc.itkey *= tblitem.itkey
       AND tblrtemp.rkey =* tblreceipt.rkey 

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

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

发布评论

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

评论(4

箹锭⒈辈孓 2024-11-10 01:13:25

*= 是左联接

=* 是右联接

您是否尝试过在 SQL Server Management Studio 的 SQL 编辑器中将其显示出来?
它可能会为您转换它。

*= is a left Join

=* is a right Join

Have you tried bringing it up in the SQL Editor in SQL Server Management Studio?
It might convert it for you.

池予 2024-11-10 01:13:25
SELECT tblacc.*
FROM   tblacc
  INNER JOIN tblreceipt ON tblacc.rkey = tblreceipt.rkey
  INNER JOIN tblst      ON tblacc.stkey = tblst.stkey
  LEFT JOIN  tblitem    ON tblacc.stkey = tblitem.stkey
                       AND tblacc.itkey = tblitem.itkey
  LEFT JOIN  tblrtemp   ON tblacc.stkey = tblrtemp.stkey
                       AND tblrtemp.rkey = tblreceipt.rkey
SELECT tblacc.*
FROM   tblacc
  INNER JOIN tblreceipt ON tblacc.rkey = tblreceipt.rkey
  INNER JOIN tblst      ON tblacc.stkey = tblst.stkey
  LEFT JOIN  tblitem    ON tblacc.stkey = tblitem.stkey
                       AND tblacc.itkey = tblitem.itkey
  LEFT JOIN  tblrtemp   ON tblacc.stkey = tblrtemp.stkey
                       AND tblrtemp.rkey = tblreceipt.rkey
溺ぐ爱和你が 2024-11-10 01:13:25

不幸的是,“ON 子句中的重载 *=, =* 子句”的含义不太清楚。但是,我可以看到一个问题:您正在使用旧式语法进行外连接。您应该将此语法替换为新的“ANSI SQL”语法。这使用关键字而不是 *==*,并将连接条件移至 FROM 子句中:

  • WHERE ax *= by 变为 FROM a LEFT OUTER JOIN b ON ax = by
  • WHERE ax =* by 变为 FROM a RIGHT OUTER JOIN b ON ax = by code>
  • 还有 FROM a FULL OUTER JOIN b ON ax = by,它用 NULL 填充任一表中不匹配的元组。

旧语法自 SQL Server 2005 以来已被弃用,因为它是非标准的并且容易引入歧义。它不适用于在 SQL Server 中运行的数据库2005 或更高版本 兼容模式,这可能是问题的根源。

It's not quite clear what you mean by "overload *=, =* clause in ON clause", unfortunately. I can see one problem, however: you are using the old-style syntax for outer joins. You should replace this syntax by the new "ANSI SQL" syntax. This uses keywords rather than *= and =*, and moves the join condition into the FROM clause:

  • WHERE a.x *= b.y becomes FROM a LEFT OUTER JOIN b ON a.x = b.y
  • WHERE a.x =* b.y becomes FROM a RIGHT OUTER JOIN b ON a.x = b.y
  • There is also FROM a FULL OUTER JOIN b ON a.x = b.y, which pads un-matched tuples from either table with NULLs.

The old syntax has been deprecated since SQL Server 2005 because it was non-standard and prone to introducing ambiguity. It is not available on databases running in SQL Server 2005 or later compatibility mode, which is likely the source of your problem.

北凤男飞 2024-11-10 01:13:25

我相信查询应该如下所示,但我不知道您是否想对表 tblreceipt< 进行 INNER JOINRIGHT JOIN /代码>。

SELECT tblacc.*
FROM   tblacc
JOIN   tblreceipt
    ON tblacc.rkey = tblreceipt.rkey
JOIN   tblst
    ON tblacc.stkey = tblst.stkey
LEFT JOIN tblrtemp
    ON tblacc.stkey = tblrtemp.stkey
LEFT JOIN tblitem
    ON tblacc.stkey = tblitem.stkey AND tblacc.itkey = tblitem.itkey
RIGHT JOIN tblreceipt
    ON tblrtemp.rkey = tblreceipt.rkey 

I believe the query should be something like below, though I don't know if you want to do an INNER JOIN and a RIGHT JOIN with the table tblreceipt.

SELECT tblacc.*
FROM   tblacc
JOIN   tblreceipt
    ON tblacc.rkey = tblreceipt.rkey
JOIN   tblst
    ON tblacc.stkey = tblst.stkey
LEFT JOIN tblrtemp
    ON tblacc.stkey = tblrtemp.stkey
LEFT JOIN tblitem
    ON tblacc.stkey = tblitem.stkey AND tblacc.itkey = tblitem.itkey
RIGHT JOIN tblreceipt
    ON tblrtemp.rkey = tblreceipt.rkey 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文