Forum Moderators: open

Message Too Old, No Replies

MS SQL Update a Field from a Field in Another Table

Can somebody help a brother out?

         

dataguy

9:43 pm on Aug 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm trying to update a field in one table with a value found in a field in another table, using SQL Server 2000. The two tables have a common ID. Everything I can find says that I should be using this:

UPDATE Table1
SET Table1.Field1 = Table2.Field2
WHERE Table1.CommonID = Table2.CommonID

I keep getting an error message that Table2 doesn't exist, or more precisely:
Server: Msg 107, Level 16, State 3, Line 1
The column prefix 'Table2' does not match with a table name or alias name used in the query.

Can anyone see what I'm doing wrong?

Small Website Guy

10:29 pm on Aug 13, 2004 (gmt 0)

10+ Year Member



Make your query look like the help text that comes with SQL Server:

UPDATE titles
SET ytd_sales = titles.ytd_sales + sales.qty
FROM titles, sales
WHERE titles.title_id = sales.title_id

You're query is missing the FROM clause.

dataguy

11:14 pm on Aug 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Perfect! Thanks...