sql find and replace

amillyard
amillyard used Ask the Experts™
on
How do you in SQL scripting do the following:

go through all rows (just once) in Table 1 -- compare column Table 1 'SerialNumber' for example with Table 2 'SerialNumber' -- if these 2 values match -- then get Table 2's 'PinCode' column and update Table 1's 'CardNumber' with the value 'PinCode'

if no match -- no update to Table 1's row (left as is with existing 'CardNumber' value.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2010
Commented:
UPDATE Table1
SET CardNumber = t2.PinCode
FROM Table1 t1 INNER JOIN
    Table2 t2 ON t1.SerialNumber = t2.SerialNumber

Author

Commented:
great - worked perfectly 1st time :-)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial