By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,647 Members | 1,331 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,647 IT Pros & Developers. It's quick & easy.

problem with comparing 2 text columns in 2 tables

P: n/a
Hi,
I have 2 tables and each has a text column. When i compared the 2
columns with the LIKE operator i found something strange.

create table test1( var1 text )
create table test2( var1 text )

insert into test1 values ( '-- [ CustomerType = 1 ]' )
insert into test2 values ( '-- [ CustomerType = 1 ]' )

select * from test1, test2
where test1.var1 like test2.var1

The last query surprisingly did not return any results. However when i
took of the '[' in the text data and had something like this

insert into test1 values ( '-- CustomerType = 1 ]' )
insert into test2 values ( '-- CustomerType = 1 ]' )

the query returned expected results, showing one row.

any helpful would be great.

Regards,
Arun Prakash. B
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On 3 Nov 2004 05:01:19 -0800, ArunPrakash wrote:
Hi,
I have 2 tables and each has a text column. When i compared the 2
columns with the LIKE operator i found something strange.

create table test1( var1 text )
create table test2( var1 text )

insert into test1 values ( '-- [ CustomerType = 1 ]' )
insert into test2 values ( '-- [ CustomerType = 1 ]' )

select * from test1, test2
where test1.var1 like test2.var1

The last query surprisingly did not return any results. However when i
took of the '[' in the text data and had something like this

insert into test1 values ( '-- CustomerType = 1 ]' )
insert into test2 values ( '-- CustomerType = 1 ]' )

the query returned expected results, showing one row.

any helpful would be great.


Hi Arun,

Yes, that's intended behaviour. Check out the description of LIKE in Books
Online, in the table listing wildcard cahracters, there's a row:

[ ] Any single character within the specified
range ([a-f]) or set ([abcdef])

So if you test is a string is LIKE '-- [ CustomerType = 1 ]', it will
return true only if that string is equal to two hashes, one space and one
character in the set {space, C, u, s, t, o, m, e, r, T, y, p, e, =, 1}.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.