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
*= 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.
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 ax *= by
becomes FROM a LEFT OUTER JOIN b ON ax = by
WHERE ax =* by
becomes FROM a RIGHT OUTER JOIN b ON ax = by
FROM a FULL OUTER JOIN b ON ax = by
, 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.
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
.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.