I'm trying to update the ACCOUNT_GROUP column in a table BILL_INFO_DETAIL from a similar column in table SERVICE_INFO that has a foreign key to BILL_INFO_DETAIL. Each BILL_INFO_DETAIL can have one SERVICE_INFO.
I tried this code, but it didn't select the proper SERVICE_INFO as the WHERE clause didn't work as I intended:
UPDATE BILL_INFO_DETAIL
SET ACCOUNT_CODE = (SELECT TOP (1) si.ACCOUNT_CODE
FROM SERVICE_INFO si
WHERE si.SERVICE_CODE = SERVICE_CODE);
All items in BILL_INFO_DETAIL's ACCOUNT_CODE got set to the first ACCOUNT_CODE of SERVICE_INFO
Seems this is not that straight forward. Please advise.