Hi,
I need to compare 2 strings from 2 different tables but there is no common
column for a join.
CREATE TABLE T1 (FirstName varchar(20), LastName varchar(20))
CREATE TABLE T2 (FirstName varchar(20), LastName varchar(20))
I created 2 temp tables (#T1 & #T2) populated with binary data for the
comparasion but not realy sure how to proceed from there...
CAST(lower(FirstName + LastName) AS VARBINARY) AS FullNameYan
create table ABCD
(
courceid smallint not null,
description varchar(20) null
)
insert into ABCD(courceid,description)values (1,'DFh2AcZ')
insert into ABCD(courceid,description)values (2,'dHZ3')
)
SELECT description FROM ABCD where
charindex(cast('H' as varbinary(20)),cast(description as varbinary(20)))> 0
"Yan" <yanive@.rediffmail.com> wrote in message
news:OU4JgyrQGHA.4920@.tk2msftngp13.phx.gbl...
> Hi,
> I need to compare 2 strings from 2 different tables but there is no common
> column for a join.
> CREATE TABLE T1 (FirstName varchar(20), LastName varchar(20))
> CREATE TABLE T2 (FirstName varchar(20), LastName varchar(20))
> I created 2 temp tables (#T1 & #T2) populated with binary data for the
> comparasion but not realy sure how to proceed from there...
> CAST(lower(FirstName + LastName) AS VARBINARY) AS FullName
>|||Sorry, I do not understand.
I need to find if any record from #T1 exists in #T2 in order to know if any
name wich exists in #T1 also exists in #T2.
--
"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:u6G0u3rQGHA.4312@.TK2MSFTNGP12.phx.gbl...
> Yan
> create table ABCD
> (
> courceid smallint not null,
> description varchar(20) null
> )
> insert into ABCD(courceid,description)values (1,'DFh2AcZ')
> insert into ABCD(courceid,description)values (2,'dHZ3')
> )
> SELECT description FROM ABCD where
> charindex(cast('H' as varbinary(20)),cast(description as varbinary(20)))>
> 0
>
>
> "Yan" <yanive@.rediffmail.com> wrote in message
> news:OU4JgyrQGHA.4920@.tk2msftngp13.phx.gbl...
>|||Yan
CREATE TABLE #T1 ( col1 VARCHAR(10)NOT NULL)
CREATE TABLE #T2 ( col1 VARCHAR(10)NOT NULL)
INSERT INTO #T1 VALUES ('Clinton')
INSERT INTO #T1 VALUES ('Bush')
INSERT INTO #T1 VALUES ('Lenin')
INSERT INTO #T1 VALUES ('Putin')
INSERT INTO #T2 VALUES ('Stalin')
INSERT INTO #T2 VALUES ('Ford')
INSERT INTO #T2 VALUES ('Lenin')
INSERT INTO #T2 VALUES ('Putin')
--SQL Server 2000
SELECT * FROM #T1
WHERE col1 NOT IN (SELECT col1 FROM #T2)
--SQL Server 2005
SELECT * FROM #T1 EXCEPT SELECT * FROM #T2;
"Yan" <yanive@.rediffmail.com> wrote in message
news:u5p1$DsQGHA.5092@.TK2MSFTNGP11.phx.gbl...
> Sorry, I do not understand.
> I need to find if any record from #T1 exists in #T2 in order to know if
> any name wich exists in #T1 also exists in #T2.
> --
>
> "Uri Dimant" <urid@.iscar.co.il> wrote in message
> news:u6G0u3rQGHA.4312@.TK2MSFTNGP12.phx.gbl...
>|||Thank you.
"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:%2361Y8LsQGHA.5924@.TK2MSFTNGP09.phx.gbl...
> Yan
> CREATE TABLE #T1 ( col1 VARCHAR(10)NOT NULL)
> CREATE TABLE #T2 ( col1 VARCHAR(10)NOT NULL)
> INSERT INTO #T1 VALUES ('Clinton')
> INSERT INTO #T1 VALUES ('Bush')
> INSERT INTO #T1 VALUES ('Lenin')
> INSERT INTO #T1 VALUES ('Putin')
> INSERT INTO #T2 VALUES ('Stalin')
> INSERT INTO #T2 VALUES ('Ford')
> INSERT INTO #T2 VALUES ('Lenin')
> INSERT INTO #T2 VALUES ('Putin')
> --SQL Server 2000
> SELECT * FROM #T1
> WHERE col1 NOT IN (SELECT col1 FROM #T2)
> --SQL Server 2005
> SELECT * FROM #T1 EXCEPT SELECT * FROM #T2;
>
>
>
>
>
> "Yan" <yanive@.rediffmail.com> wrote in message
> news:u5p1$DsQGHA.5092@.TK2MSFTNGP11.phx.gbl...
>|||On Wed, 8 Mar 2006 17:06:03 +0200, "Yan" <yanive@.rediffmail.com>
wrote:
>I need to find if any record from #T1 exists in #T2 in order to know if any
>name wich exists in #T1 also exists in #T2.
SELECT *
FROM T1
WHERE EXISTS
(select * from T2
where T1.FirstName = T2.Firstname
and T1.LastName = T2.LastName)
Using IN is fine when you only have one column to test. When you have
two columns to test EXISTS is much preferred. You really do NOT want
to concatenate strings together for testing unless there is very
special reason to, such as strange data.
Roy Harvey
Beacon Falls, CT
No comments:
Post a Comment