Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Update a table from other tables

Author  Topic 

AndyG2005
Starting Member

3 Posts

Posted - 2010-05-25 : 12:34:51
Hi there,

I am trying to update a table on my website from a number of other tables :

UPDATE
products
SET
p.products_quantity = updte.QTY,
p.products_model = updte.STKCODE,
FROM
products p
join website_update updte on p.products_model = updte.STKCODE
INNER JOIN View_GradedItems graded on graded.STKCODE = updte.STKCODE
WHERE
updte.STKCODE in ( select distinct products_model from webTEST...products )
AND updte.STKCODE like '92%'

The only problem I have is that this updates the entire products table with the same data from the first row of the from part of the query.

Can anyone see anything really obvious I am doing wrong!

Thanks

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-05-25 : 13:18:43
obvious?
There is a wrong comma.
There are 3 dots webTEST...products.
You are trying to update p.products_model when it is already the same as in updte.STKCODE because that is a join condition.

Looks senseless to me.

If you can give table structure, example data and wanted result then we can help.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

AndyG2005
Starting Member

3 Posts

Posted - 2010-05-26 : 07:02:47
Okay,

I have a table called products on my website ( using linked server )

I want to update the products information on the website table products.

I have the update information on my local server in two tables, graded stock and website update.

I want to update qty on the products table on the website.

The problem is although I join the products table, it seems to update the entire website products table with the first item in the from table
Go to Top of Page

AndyG2005
Starting Member

3 Posts

Posted - 2010-05-26 : 07:04:07
I would like product 1234 in the products table to be updated from a local table or joined table which has a matching stockcode 1234 and update the products qty with local table / join qty/

Go to Top of Page
   

- Advertisement -