0

These table descriptions are vague to protect the data I am working with. I apologize in advance but i must keep the details limited. I'm using SQL Server 2008.

I have 2 tables that look like this:

Table 1:

Facility, Person, ID, Group

Table 2:

ID, Type, Date

I want to update the Group in Table 1 based on the Type in Table 2, but only where it matches a certain Facility.

I tried this:

UPDATE Table 1
SET Group = 'Big'
FROM Table 1 T1 
INNER JOIN Table 2 T2 on T1.ID = T2.ID
WHERE Type = 'B' AND Facility LIKE '%Game%'`

But the result is an update to all the fields with Facility like '%Game%'.

A SELECT statement returns all the correct results. I am unsure what is wrong.

Thanks for any help.

4

1 回答 1

0

You are very close. You just want to use the alias in the update rather than the table name:

UPDATE T1
    SET Group = 'Big'
    from Table 1 T1 INNER JOIN
         Table 2 T2
         on T1.ID = T2.ID
    WHERE Type = 'B' AND Facility like '%Game%'
于 2013-07-15T20:51:36.177 回答