I have two tables zipTbl and locationTBl with four common columns
zipCode
City
stateCode
salesTaxRate
If the zipCode changes in the locationTbl say from '91311' to '10172' I want the city, stateCode, salesTaxRate in the locationTBL to be updated with the same values in the zipTbl where the zipCode is the new value '10172'
zipCode is the primary key for the zipTbl and a foreign key in the locationTbl.
I use the following to create a trigger but it only updates from the first row in the zipTBL not the row with the new zipCode
CREATE TRIGGER trg_update_city_state on dbo.locationTbl
AFTER Update
AS
BEGIN
UPDATE locationTbl
SET locationTbl.city = zipTbl.city,
LocationTbl.stateCode = zipTbl.stateCode,
locationTbl.salesTaxRate = zipTbl.salesTaxRate
FROM zipTbl
END
I have tried several combinations of adding "where locationTbl.zipCode = zipTbl.zipcode," but I keep getting syntax errors