You are here: Re: Inner Join Problem « MsSQL Server « IT news, forums, messages
Re: Inner Join Problem

Posted by Gert-Jan Strik on 12/14/06 19:27

The ANSI SQL compliant rewrite of this query would be:

UPDATE Products
SET Stock = (
SELECT Products.Stock - OrdersProducts.Quantity
FROM OrdersProducts
WHERE OrdersProducts.ProductID = Products.ProductID
AND OrdersProducts.OrderID=63116
)
WHERE EXISTS (
SELECT *
FROM OrdersProducts
WHERE OrdersProducts.ProductID = Products.ProductID
AND OrdersProducts.OrderID=63116
)

Since this is standard SQL, it will run on any SQL Server installation,
and should run on any modern RDBMS. It might even run in MS Access.

HTH,
Gert-Jan


"info@bodykind.com" wrote:
>
> The following query works fine in access and does exactly what I want
> it to do however I get a syntax error when I port it over to SQL Server
> 2000.
>
> -------------
>
> UPDATE OrdersProducts INNER JOIN Products ON OrdersProducts.ProductID =
> Products.ProductID SET Products.Stock =
> Products.Stock-OrdersProducts.Quantity
> WHERE OrdersProducts.OrderID=63116
>
> --------------
>
> Any help would be greatly appreciated
>
> Many thanks

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация