sql server 2005 - Self join/update of table with data in same table -
due combining old , new system data in table have list of data this:
work no work name ========= ========= 123456 james 123456 james, (123456)
and want update to:
work_no work_name ========= ========= 123456 james 123456 james
i tried building update statement, wasn't confident in ran equivalent select statement see returned , seems running in infinite loop (there's 200k records , when stopped it @ somewhere in 2 million returned!) although returning @ start looked fine seemed duplicating or something:
update c1 set c1.work_name = c.work_name table c1 inner join table c on c1.work_no = c.work_no charindex(',',c1.work_name) > 0
only got experience doing simplest update statements - bit stuck 1 if suggest doing wrong , best way rectify it?
thanks
andrew
do have index built on work_no? did try:
update #table set work_name = (select top 1 c.work_name #table c #table.work_no = c.work_no , charindex(',',c.work_name) = 0) charindex(',',c.work_name) > 0
Comments
Post a Comment