June 22, 2006 at 8:39 am
UPDATE [v2_beta_small].[dbo].[beta]
set [v2_beta_small].[dbo].[beta].[prv_location] = [v2_lookup].[dbo].[nsg06may].[location]
from [v2_beta_small].[dbo].[beta]
join [v2_lookup].[dbo].[nsg06may].[col016] on replace(replace( [v2_lookup].[dbo].[nsg06may].[location],' ',''),' ','') = replace(replace([v2_beta_small].[dbo].[beta].[prv_location],' ',''),' ','')
June 22, 2006 at 8:49 am
I think 2 things can be done here.
1. access remote db from link server.
2. First dump all the records in #temp table from select & then update the main table from the #temp table.
------------
Prakash Sawant
http://psawant.blogspot.com
June 22, 2006 at 9:23 am
Question:
What exactly is [v2_lookup].[dbo].[nsg06may].[col016] ?
It is in the part of the query where a table is expected, but the 4-part naming indicates either a linked server (in which case [dbo] is in the wrong location) or a table column, in which case you should get a syntax error due to coding a column object where a table is expected.
Secondly, using a series of functions on the joined columns eliminates the possibility of an index seek operation.
June 22, 2006 at 9:44 am
Question:
What exactly is [v2_lookup].[dbo].[nsg06may].[col016]
an error in typing, in the actual query it reads [v2_lookup].[dbo].[nsg06may]
i will look at dealing with the functions as I did not realise they would affect the index seek!!!
Thanks for both your help so far...
June 22, 2006 at 10:25 am
You can also make things easier on yourself (and anyone else reading the code) by using table aliases:
UPDATE t1
SET [prv_location] = t2.[Location]
FROM [v2_beta_small].[dbo].[beta] As t1
INNER JOIN [v2_lookup].[dbo].[nsg06may] As t2
ON (
replace(replace(t2.[location],' ',''),' ','') =
replace(replace(t2.[prv_location],' ',''),' ','')
)
June 22, 2006 at 10:34 am
i agree with the table aliases, do ordinarily, but stopped on updates because of some problems referncing the update table, but will start again and see
as to the update query...
I removed the spaces from the join columns using an update and ran the query without the repalce functions - it now works a treat
thanks ever so much
June 22, 2006 at 10:42 am
Don't forget you will need to change the processes which populate the column. You should also enforce any check constraints you can ( eg not like '% %'). A temporary solution might be to define calc columns using the replace() function, then index those columns.
Tim Wilkinson
"If it doesn't work in practice, you're using the wrong theory"
- Immanuel Kant
June 26, 2006 at 2:32 am
And as a general remark: As long as you have functions (replace, substring...) in your WHERE or ON clauses the optimiser would never use any indexes.
Bye
Gabor
June 26, 2006 at 2:43 am
yes, thank you I realise this now.
We are currently taking steps to redesign the database and the queries to deal with this.
Thanks again!
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply