This seems really straight forward, and I think I just want to validate and ensure that I’m doing this correctly.
Basically I want to run an UPDATE on these records:
SELECT contact.company, contact.coaddress, contact.costate, contact.cocity, contact.cozip, contact.phonebusiness, dial.AgentID, dial.Attempts, dial.CRC
FROM contact LEFT OUTER JOIN
dial ON contact.DialID = dial.DialID
WHERE (dial.AgentID > '-1') AND (contact.cozip LIKE '600%' OR
contact.cozip LIKE '601%' OR
contact.cozip LIKE '606%' OR
contact.cozip LIKE '608%' OR
contact.cozip LIKE '605%' OR
contact.cozip LIKE '604%' OR
contact.cozip LIKE '613%' OR
contact.cozip LIKE '611%')
I get back my correct results on the SELECT statement. I need to now UPDATE those records:
UPDATE dial
SET ProjectID = '60'
FROM dial INNER JOIN
contact ON dial.DialID = contact.DialID
WHERE (dial.AgentID > '-1') AND (contact.cozip LIKE '600%' OR
contact.cozip LIKE '601%' OR
contact.cozip LIKE '606%' OR
contact.cozip LIKE '608%' OR
contact.cozip LIKE '605%' OR
contact.cozip LIKE '604%' OR
contact.cozip LIKE '613%' OR
contact.cozip LIKE '611%')
Does this look correct? Is there a more efficient way of doing this?
Yes, this looks correct.
There are some LIKE tricks and I like aliases personally. The alias d makes it clear which table is being updated in the JOIN. The [] in the LIKE means a range or set
Should AgentID be the number -1 too?