I have a table where multiple records have the same LocationID. Some of these records have a 'true' value in the 'UsedinSA' field. I want to set all of the 'PartofContract' values to 'true' if there is one corresponding record with the same 'LocationID' and a 'true' value in 'UsedinSA'.
I've attempted as follows but this only updates the records that are already 'true'.
UPDATE tbAsset
SET tbAsset.PartofContract = 1
WHERE LocationID IN (SELECT dbo.tbAsset.LocationID FROM dbo.tbasset where tbAsset.UsedinSA = 1)
As an example of the data:
LocationID UsedinSA PartofContract
- 156311 0 0
- 156310 0 0
- 156309 1 1
- 156309 0 0
Record 4 should have 'PartofContract' set to 'True' because record 3 is and they have the same 'LocationID'.
Thanks in advance
Matt