Skip to content
Advertisement

Need to Update Offdate of Component Only Where it’s Used Alongside Another Component

I need to update the offdate of a component (322058-000000′) of a parent part where the component in questions is used along with another component.

The following code gives me the component (322058-000000) and the instance where it needs to be changed. It needs to be changed where it is used along with component (322123-301200).

select * from BomStructure BS
where 
Component = '322058-000000' and
exists (select 1 from BomStructure 
        where ParentPart = BS.ParentPart and Component = '322123-301200');

I only want to update the offdate for component 322058-000000 as per the results of the query above. Please assist.

Advertisement

Answer

Unless I’m missing something here, assuming the result of your existing query is the row or rows you want to update, you just need to convert your SELECT statement into an UPDATE statement.

UPDATE BS
SET OffDate = <The value you need here>
from BomStructure BS
where 
Component = '322058-000000' and
exists (select 1 from BomStructure 
        where ParentPart = BS.ParentPart and Component = '322123-301200');
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement