x

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
82 2 2 2

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

10 answers: sort voted first

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

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
1.1k 2 2

(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

@atoz

 SELECT Key FROM AboveTable WHERE 'fried' LIKE '%'+[Key]+'%' 
more ▼

answered Jan 09 '10 at 12:13 AM

Scot Hauder gravatar image

Scot Hauder
5.9k 13 15 18

(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
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.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

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

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x977
x22

asked: Nov 12 '09 at 04:35 PM

Seen: 19252 times

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