I have a table called service entry which has a field called part description, Sample data is as follows:
**dbo.ServiceEntry**
ID PartDescription
1200 60009 ~ Slide Error ~ L 0 ~ P 0 | 60011 ~ RV loader - Pick/Place Homing Error ~ L 0 ~ P 0
I then have a table called ServiceEntryPart which has a 1 to many relationship, one service entry can have multiple parts in it, hence the service entry part table
**dbo.ServiceEntryPart**
ID ServiceEntry PartID OldPartID
1 1200 5000 60009
2 1200 5500 60011
**dbo.Part**
ID Description OldPartID
5000 New Slide Description 60009
5500 Xyz 60011
Im trying to write a script to update the partdescription column in the ServiceEntry Table so the expected results will look like following with the new part id. so its basically just replacing the old part ids with the new ones
OLD OUTPUT
60009 ~ Slide Error ~ L 0 ~ P 0 | 60011 ~ RV loader - Pick/Place Homing Error ~ L 0 ~ P 0
NEW OUTPUT
5000 ~ New Slide Description ~ L 0 ~ P 0 | 5500 ~ Xyz ~ L 0 ~ P 0
I need some help with the script.query to update this fields with the new part id if present:
1. Get the existing field
DECLARE @PartDescription VARCHAR(8000)
SELECT @PartDescription = PartDescription FROM
ServiceEntry
2. UPDATE ServiceEntry
SET PartDescription
1 Answer