Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Join on nvarchar column using LIKE Expand / Collapse
Author
Message
Posted Tuesday, January 22, 2013 12:49 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, July 7, 2014 6:22 AM
Points: 231, Visits: 721
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.
Post #1409840
Posted Tuesday, January 22, 2013 12:59 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Friday, September 12, 2014 9:43 AM
Points: 6,719, Visits: 13,824
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 %?


“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

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
Exploring Recursive CTEs by Example Dwain Camps
Post #1409841
Posted Tuesday, January 22, 2013 1:05 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, August 19, 2014 12:26 AM
Points: 2,840, Visits: 3,963
praveen_vejandla (1/22/2013)
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.
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
Post #1409844
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse