views:

27

answers:

2

Hi, SQL Server novice here.

UPDATE dbo.ObjectivesApproved  
SET dbo.ObjectivesApproved.VAP = 'Y'
WHERE ((dbo.Approved.Cri_Group In ('X01' ,'X02' ,'X03' ,'X04' ,'X05' ,'X07' ,'X08' ,'X09' ,'X10' ,'X11' ,'X12' ,'X13' ,'X14')))

gives the following error

The multi-part identifier "dbo.Approved.Cri_Group" could not be bound.

What's causing the error?

Update: The above query was a result of trial and error. I'm updating an Access Application to SQL server, and having some trouble with the slightly different dialects of SQL

This is my original Query.

UPDATE dbo.Approved 
INNER JOIN dbo.ObjectivesApproved ON dbo.Approved.ID = dbo.ObjectivesApproved.ID 
SET dbo.ObjectivesApproved.VAP = 'Y'
WHERE ((dbo.Approved.Cri_Group 
In ('X01' ,'X02' ,'X03' ,'X04' ,'X05' ,'X07' ,'X08' ,'X09' ,'X10' ,'X11' ,'X12' ,'X13' ,'X14')));

This gives the error - Incorrect syntax near the keyword 'INNER'

thanks

+1  A: 

You are not specifying that the update also uses the Approved table anywhere, instead you just go ahead and use one if its columns.

On another note, your update looks logically flawed too as you'll update the ObjectivesApproved records irrespective of what they contain, i.e. there is no relation mentioned between ObjectivesApproved and Approved.

CyberDude
+2  A: 

That would translate into

UPDATE
    OA
SET
    OA.VAP = 'Y'
FROM
    dbo.Approved AS A
    INNER JOIN dbo.ObjectivesApproved OA ON A.ID = OA.ID
WHERE
    A.Cri_Group IN ('X01' ,'X02' ,'X03' ,'X04' ,'X05' ,'X07' ,'X08' ,'X09' ,'X10' ,'X11' ,'X12' ,'X13' ,'X14')
CyberDude
+1, this should fix your problem. Read up on table aliasing if your confused about why it looks so different.
Abe Miessler