x
login about faq Site discussion (meta-askssc)

Use LIKE where matching pattern is a column value plus a wildcard?

We have two lists to compare, so I need to compare the data in the column against the data in the other column, and I'd like to use LIKE to do it. I used the syntax of "where col1 like col2 + '%' and it doesn't bomb, but it doesn't return any rows, either, and it should.

more ▼

asked Nov 12 '09 at 04:35 PM in Default

DonnaB gravatar image

DonnaB
41 2 2 2

(comments are locked)
10|1200 characters needed characters left

10 answers: sort voted first

Personally I have always found LEFT(col, length) to be quicker than LIKE 'value%' - but others swear blind that the exact opposite is true. If you just want the value you're searching for to be at the start, it's worth trying, because the performance of both methods can be variable...

more ▼

answered Nov 12 '09 at 06:25 PM

Matt Whitfield gravatar image

Matt Whitfield ♦♦
29.2k 56 63 87

(comments are locked)
10|1200 characters needed characters left
SELECT USR.USER_ID, USR.LDAP_TITLE, LRM.LDAP_ROLE, LRM.ROLE_ID, RLS.PRIMARY_ROLE
FROM USERS USR, NEW_LDAP_ROLE_MATCH LRM, NEWROLES RLS
WHERE (INSTR(USR.LDAP_TITLE,LRM.LDAP_ROLE) > 0) 
AND LRM.ROLE_ID = RLS.ROLE_ID; 

Late reply but i guess it might hel someone later.

more ▼

answered Apr 06 '11 at 03:03 AM

Naziya gravatar image

Naziya
1

(comments are locked)
10|1200 characters needed characters left

I'd definitely be interested in the datatypes. Have you tried moving the location of DM.KeyIndicator = 'O' to the WHERE clause? Sometimes that positioning does make a difference.

more ▼

answered Nov 13 '09 at 11:29 AM

Jack Corbett gravatar image

Jack Corbett
1.1k 2 2 3

(comments are locked)
10|1200 characters needed characters left

Here is the situation..
=============
id key
=============
1 bo
2 fr
=============
..and i would like to query something like " where %column% = criteria.

Example: If i query for 'aboz', it would return row 1 (from above table) as result and if i query for 'fried', it would return row 2 (from above table) as result. It's the opposite with common situation. Is this the similar problem with yours? I've been looking for solution from weeks ago..

more ▼

answered Jan 05 '10 at 12:05 AM

atoz gravatar image

atoz
1

(comments are locked)
10|1200 characters needed characters left

We have a similar problem here. The main difference is that we're using MS-Dynamics. This forces the character fields to be CHAR and not VARCHAR, or NVARCHAR (Dynamics does not support Unicode). Because of this we need to do LTRIM or RTRIM on the fields when we're using one like another.

more ▼

answered Nov 13 '09 at 02:50 PM

dvroman gravatar image

dvroman
500 1 2

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x914
x21

asked: Nov 12 '09 at 04:35 PM

Seen: 15036 times

Last Updated: Nov 13 '09 at 02:42 PM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.