all groups > sql server programming > november 2005 >
You're in the

sql server programming

group:

comparing two varchar variable


comparing two varchar variable mtv
11/13/2005 9:36:02 PM
sql server programming:
Table One has for column id = 'AAA-BBB-CCC' , 'AAA-BBB-DDD'
Table Two has column id = 'AAA-BBB-CCCI' , 'AAA-BBB-DDDI'

I want to return all Table One.id which appear in table Two.id by comparing
the varchar column e.g
select One.id from One, Two
where One.id like (Two.id + '%')

Re: comparing two varchar variable Ben Nevarez
11/13/2005 10:08:21 PM

Maybe this?

select * from one where id in (select id from two)

Ben Nevarez


[quoted text, click to view]

Re: comparing two varchar variable mtv
11/13/2005 10:19:01 PM
Thank you Ben but I believe it will not work. Ids in table Two has one
additional letter in the end.
cheers
mtv

[quoted text, click to view]
Re: comparing two varchar variable SriSamp
11/14/2005 11:59:03 AM
Would something like this help?
=====
CREATE TABLE test1
(
colA VARCHAR(10)
)
GO
CREATE TABLE test2
(
colB VARCHAR(10)
)
GO
INSERT INTO test1 SELECT 'AAABBBCCC'
INSERT INTO test1 SELECT 'XXXYYYZZZ'
INSERT INTO test2 SELECT 'AAABBBCCCD'
GO
SELECT
test1.colA, test2.colB
FROM
test1
INNER JOIN test2 ON test1.colA = LEFT (test2.colB, 9)
=====
--
HTH,
SriSamp
Email: srisamp@gmail.com
Blog: http://blogs.sqlxml.org/srinivassampath
URL: http://www32.brinkster.com/srisamp

[quoted text, click to view]

AddThis Social Bookmark Button