Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Batch Update(records from other table w/ priority)

Author  Topic 

yaga
Starting Member

8 Posts

Posted - 2009-08-17 : 02:57:45
Good day,
Can you give me a better solution. This is my current code look like

update master_customer set
lastname = isnull(c2.lastname, c1.lastname),
firstname = isnull(c2.firstname, c1.firstname),
middlename = isnull(c2.middlename, c1.middlename),
gender = isnull(c2.gender, c1.gender),
age = isnull(c2.age, c1.age)
from
master_customer c1, (select * customer order by customer.priority) c2
where
c1.cust_id = c2.cust_id

What I want to happen is master_customer table should have only one record per cust_id, getting each field
(with prioritization based on priority column of customer) from customer table which contains several
records per cust_id. Both table contains atleast 50 columns and customer table contains atleast 300,000
records which makes

"update master_customer set
lastname = (select top 1 lastname from customer where customer.cust_id = master_customer.cust_id order by priority),
firstname = (select top 1 firstname from customer where customer.cust_id = master_customer.cust_id order by priority),
..."

not applicable. Any suggestions?

thanks

yaga
Starting Member

8 Posts

Posted - 2009-08-17 : 03:36:51
"update master_customer set
lastname = isnull(c2.lastname, c1.lastname),
firstname = isnull(c2.firstname, c1.firstname),
middlename = isnull(c2.middlename, c1.middlename),
gender = isnull(c2.gender, c1.gender),
age = isnull(c2.age, c1.age)
from
master_customer c1, (select * customer order by customer.priority) c2
where
c1.cust_id = c2.cust_id"

I forgot to mention the problem that I'm getting using the above code, it does not follow the prioritization and sometimes it also does not get field value that are available on customer table.
Go to Top of Page
   

- Advertisement -