0

I would like to update 2 fields values from one record to a set of records in the same table:

I tryed this:

UPDATE dd SET dd.comment = y.comment, dd.author = y. author
FROM Table1 dd LEFT OUTER JOIN
(SELECT * FROM Table1 WHERE Idx=1234) y
ON dd.vin = y.vin
WHERE dd.vin like '%WLS%'

vin and idx fields are unique keys
My desire is to have the fields comment and author updated from the record which has idx=1234 to all the records whic contain in field vin 'WLS' string.
thanks in advance

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Teofil
0
UPDATE Table1 
SET comment = isnull((select comment FROM Table1 y WHERE y.Idx=1234 and table1.vin = y.vin),comment),
author = isnull((select author FROM Table1 y WHERE y.Idx=1234 and table1.vin = y.vin), author)
WHERE vin like '%WLS%'

Check the logic, test. Close thread if this solves it.

0
UPDATE Table1 
SET comment = isnull((select comment FROM Table1 y WHERE y.Idx=1234 and table1.vin = y.vin),comment),
author = isnull((select author FROM Table1 y WHERE y.Idx=1234 and table1.vin = y.vin), author)
WHERE vin like '%WLS%'

Check the logic, test. Close thread if this solves it.

Very nice solution!!!
Teo

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.