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
 query not bound?

Author  Topic 

corgiii
Starting Member

4 Posts

Posted - 2010-03-03 : 18:53:55
i'm trying to update a column of a table by selecting two different values from 2 different tables, i'm doing -


UPDATE table_temp
SET sum = table_temp.Point - table_RATING.Point




and when trying that it pops up an error saying



The multi-part identifier "table_RATING.Point" could not be bound.




does anyone know what i'm doing wrong and show some examples?

ms65g
Constraint Violating Yak Guru

497 Posts

Posted - 2010-03-03 : 19:14:50
you must use a correlated scalar subquery instead of column name of another table
Or you can use join

See:

JOIN
UPDATE T
SET sum = T1.Point - T2.Point
FROM table_temp T1
JOIN table_RATING T2
ON T1.id = T2.id


Subquery:
UPDATE T
SET sum = T.Point - (SELECT Point FROM table_RATING WHERE id = T.id
FROM table_temp T
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-03-04 : 02:17:06
quote:
Originally posted by ms65g

you must use a correlated scalar subquery instead of column name of another table
Or you can use join

See:

JOIN
UPDATE T
SET sum = T1.Point - T2.Point
FROM table_temp T1
JOIN table_RATING T2
ON T1.id = T2.id


Subquery:
UPDATE T
SET sum = T.Point - (SELECT Point FROM table_RATING WHERE id = T.id
FROM table_temp T



In the first example

UPDATE T

should be

UPDATE T1

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2010-03-04 : 07:49:54
quote:
Originally posted by ms65g

you must use a correlated scalar subquery instead of column name of another table
Or you can use join

See:

JOIN
UPDATE T
SET sum = T1.Point - T2.Point
FROM table_temp T1
JOIN table_RATING T2
ON T1.id = T2.id


Subquery:
UPDATE T
SET sum = T.Point - (SELECT Point FROM table_RATING WHERE id = T.id
FROM table_temp T




Missing Closed Brace in SubQuery

UPDATE T
SET sum = T.Point - (SELECT Point FROM table_RATING WHERE id = T.id)
FROM table_temp T
Go to Top of Page
   

- Advertisement -