January 22, 2013 at 12:49 am
UPDATE LII
SET value_exists = 1
FROM LII od
JOIN VPL sl
ON (sl.it like '%' + od.value + '%'
AND od.opr = 9 )
WHERE od.tn = 'VPL'
AND od.cn = 'it'
Is there anyway to rewrite above query for improved performance? I am joining two nvarchar columns (it, value) using LIKE and it seems very slow.
Thanks.
January 22, 2013 at 12:59 am
UPDATE od
SET value_exists = 1
FROM LII od
INNER JOIN VPL sl
ON sl.it LIKE '%' + od.value + '%'
WHERE od.tn = 'VPL'
AND od.cn = 'it'
AND od.opr = 9
The LIKE operator used with a wildcard on the left hand side of the search expression makes the join non-SARGable (Google it), which results in a table scan of table VPL. Do you really need the leading %?
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
January 22, 2013 at 1:05 am
praveen_vejandla (1/22/2013)
UPDATE LIISET value_exists = 1
FROM LII od
JOIN VPL sl
ON (sl.it like '%' + od.value + '%'
AND od.opr = 9 )
WHERE od.tn = 'VPL'
AND od.cn = 'it'
Is there anyway to rewrite above query for improved performance? I am joining two nvarchar columns (it, value) using LIKE and it seems very slow.
Thanks.
send the index deifnition of Lil and VPL table
-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply