简体   繁体   English

从SQL 2000到SQL 2008

[英]SQL 2000 to SQL 2008

I have a query in SQL 2000 DB and I need to migrate it to SQL 2008 DB. 我在SQL 2000 DB中有一个查询,我需要将其迁移到SQL 2008 DB。 It works fine in SQL2000 and I j't need to revamp it into SQL2008. 它在SQL2000中可以正常工作,我不需要将其改编为SQL2008。 Below is the query in SQL2000. 下面是SQL2000中的查询。 Please guide me how can we overload *= , =* clause in ON clause. 请指导我如何在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 

*= is a left Join * =是左联接

=* is a right Join = *是正确的加入

Have you tried bringing it up in the SQL Editor in SQL Server Management Studio? 您是否尝试过在SQL Server Management Studio的SQL编辑器中启动它? It might convert it for you. 它可能会为您转换。

It's not quite clear what you mean by "overload *= , =* clause in ON clause", unfortunately. 不幸的是,您不清楚“在ON子句中重载*==*子句”是什么意思。 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 . 您应该用新的“ ANSI SQL”语法替换此语法 This uses keywords rather than *= and =* , and moves the join condition into the FROM clause: 这使用关键字而不是*==* ,并将连接条件移到FROM子句中:

  • WHERE ax *= by becomes FROM a LEFT OUTER JOIN b ON ax = by WHERE ax *= by FROM a LEFT OUTER JOIN b ON ax = by变为FROM a LEFT OUTER JOIN b ON ax = by
  • WHERE ax =* by becomes FROM a RIGHT OUTER JOIN b ON ax = by WHERE ax =* by FROM a RIGHT OUTER JOIN b ON ax = by变为FROM a RIGHT OUTER JOIN b ON ax = by
  • There is also FROM a FULL OUTER JOIN b ON ax = by , which pads un-matched tuples from either table with NULLs. FROM a FULL OUTER JOIN b ON ax = by还有FROM a FULL OUTER JOIN b ON ax = by ,它用NULL填充任一表中不匹配的元组。

The old syntax has been deprecated since SQL Server 2005 because it was non-standard and prone to introducing ambiguity. 自SQL Server 2005起不赞成使用旧语法,因为它是非标准语法,容易引入歧义。 It is not available on databases running in SQL Server 2005 or later compatibility mode, which is likely the source of your problem. 在以SQL Server 2005或更高版本的兼容模式运行的数据库上不可用 ,这很可能是问题的根源。

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

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 . 我相信查询应该像下面这样,尽管我不知道您是否想对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 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM