What is the best way to update multiple fields in a record only if the values are different?
Ive tried the following two scripts to only receive errors...
############# 1 ##################
UPDATE tbl_title
set
retail_us = tbl_scan_temp.retail_us
where (retail_us <> tbl_scan_temp.retail_us) and (tbl_scan_temp.retail_us is not null),
bisac_code = tbl_scan_temp.bisac_code
where (bisac_code <> tbl_scan_temp.bisac_code) and (tbl_scan_temp.bisac_code is not null),
length = tbl_scan_temp.length
where (t.length <> tbl_scan_temp.length) and (tbl_scan_temp.length is not null) ,
width = tbl_scan_temp.width
where (t.width <> tbl_scan_temp.width) and (tbl_scan_temp.width is not null)
FROM tbl_scan_temp
INNER JOIN tbl_title t ON t.isbn = tbl_scan_temp.isbn
############# 2 ##################
UPDATE tbl_title
if (retail_us <> tbl_scan_temp.retail_us) and (tbl_scan_temp.retail_us is not null) then
set retail_us = tbl_scan_temp.retail_us
if (bisac_code <> tbl_scan_temp.bisac_code) and (tbl_scan_temp.bisac_code is not null)then
set bisac_code = tbl_scan_temp.bisac_code
if (t.length <> tbl_scan_temp.length) and (tbl_scan_temp.length is not null) then
set length = tbl_scan_temp.length
if (t.width <> tbl_scan_temp.width) and (tbl_scan_temp.width is not null) then
set width = tbl_scan_temp.width
FROM tbl_scan_temp
INNER JOIN tbl_title t ON t.isbn = tbl_scan_temp.isbn
The temp table is always thousands of records, so I hope it is clear by my poor efforts that I only want to chnge the value if it is valuable and without cycling the tables more than once.
Thanks for your help once again.
[blue]Kathy[/blue]
When you dig another out of their troubles, you find a place to bury your own.—Anonymous
The person who says it can't be done shouldn't interrupt the person who is doing it.—Chinese Proverb
Ive tried the following two scripts to only receive errors...
############# 1 ##################
UPDATE tbl_title
set
retail_us = tbl_scan_temp.retail_us
where (retail_us <> tbl_scan_temp.retail_us) and (tbl_scan_temp.retail_us is not null),
bisac_code = tbl_scan_temp.bisac_code
where (bisac_code <> tbl_scan_temp.bisac_code) and (tbl_scan_temp.bisac_code is not null),
length = tbl_scan_temp.length
where (t.length <> tbl_scan_temp.length) and (tbl_scan_temp.length is not null) ,
width = tbl_scan_temp.width
where (t.width <> tbl_scan_temp.width) and (tbl_scan_temp.width is not null)
FROM tbl_scan_temp
INNER JOIN tbl_title t ON t.isbn = tbl_scan_temp.isbn
############# 2 ##################
UPDATE tbl_title
if (retail_us <> tbl_scan_temp.retail_us) and (tbl_scan_temp.retail_us is not null) then
set retail_us = tbl_scan_temp.retail_us
if (bisac_code <> tbl_scan_temp.bisac_code) and (tbl_scan_temp.bisac_code is not null)then
set bisac_code = tbl_scan_temp.bisac_code
if (t.length <> tbl_scan_temp.length) and (tbl_scan_temp.length is not null) then
set length = tbl_scan_temp.length
if (t.width <> tbl_scan_temp.width) and (tbl_scan_temp.width is not null) then
set width = tbl_scan_temp.width
FROM tbl_scan_temp
INNER JOIN tbl_title t ON t.isbn = tbl_scan_temp.isbn
The temp table is always thousands of records, so I hope it is clear by my poor efforts that I only want to chnge the value if it is valuable and without cycling the tables more than once.
Thanks for your help once again.
[blue]Kathy[/blue]
When you dig another out of their troubles, you find a place to bury your own.—Anonymous
The person who says it can't be done shouldn't interrupt the person who is doing it.—Chinese Proverb