TSQL - Need correct syntax

He Experts,

I have this:
Select ClientCT, CountryName
From cnv_CTXfer
Where ClientCT In (Select Distinct TxtCountry From tblSIOP)

Open in new window

Checking if a match works fine.

But when I want to check Not matching:
Select ClientCT, CountryName
From cnv_CTXfer
Where ClientCT Not In (Select Distinct TxtCountry From tblSIOP)

Open in new window


I don't get any records what am I doing wrong?  I know that I should get 7 records.

Please help and thanks...
Amour22015Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

plusone3055Commented:
Select ClientCT, CountryName
From cnv_CTXfer
Where ClientCT NOT EXISTS  (Select Distinct TxtCountry From tblSIOP)

Open in new window

0
Amour22015Author Commented:
I get a syntax error:
Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'EXISTS'.

Please help and thanks
0
plusone3055Commented:
You Could also do it this way

Select ClientCT, CountryName
From cnv_CTXfer     as T1
LEFT JOIN  tlbSIOP  as  T2
ON     T2.(commonIdHere) =   T1.(commonIDHere)
WHERE  T2.ClientCT IS NULL  -- if your looking for NULL ClientCT  Column in tlbSIOP 

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

plusone3055Commented:
SELECT ClientCT, CountryName
FROM   cnv_CTXfer
WHERE   NOT EXISTS
        (
        SELECT  NULL
        FROM    tlbSIOP  as  T1
        WHERE   t1.txtcountry= cnv_CTXfer.ClientCT
        )

Open in new window

0
plusone3055Commented:
sorry was doing it from a phone originally
I made Typos and incomplete
Here you go :)
SELECT ClientCT, CountryName
FROM   cnv_CTXfer
WHERE   NOT EXISTS
        (
        SELECT  NULL
        FROM    tlbSIOP  as  T1
        WHERE   t1.txtcountry = cnv_CTXfer.ClientCT
        )

Open in new window




that should work
0
Amour22015Author Commented:
But that only takes care of Nulls

I need to find Not equal where not nulls so:
WHERE  T2.ClientCT IS NULL

Would be:
WHERE  T2.ClientCT IS NOT NULL

But that returns all equal, I have manually taken care of 3 more records.
0
plusone3055Commented:
okay im sure we can resolve :)

Please paste in which query you used
and I will alter
0
Amour22015Author Commented:
Thanks,
SELECT ClientCT, CountryName
FROM   cnv_CTXfer
WHERE   NOT EXISTS
        (
        SELECT  txtCountry
        FROM    tblSIOP  as  T1
        WHERE   t1.txtcountry <> cnv_CTXfer.ClientCT
        )

Open in new window


But that only gives where there is a null value.

I am looking for when there is not a match on:
t1.txtcountry <> cnv_CTXfer.ClientCT
0
plusone3055Commented:
SELECT ClientCT, CountryName
FROM   cnv_CTXfer
WHERE   NOT EXISTS
        (
        SELECT  txtCountry
        FROM    tblSIOP  as  T1
        WHERE   t1.txtcountry <> cnv_CTXfer.ClientCT
        AND      t1.txtcountry <> '' 
        )

Open in new window

0
Amour22015Author Commented:
Actually I think I worked it out:
SELECT Distinct txtCountry
FROM   tblSIOP
WHERE   NOT EXISTS
        (
        SELECT  txtCountry
        FROM    cnv_CTXfer  as  T1
        WHERE   txtcountry = T1.ClientCT
        )

Open in new window


but I will check your post also.
0
plusone3055Commented:
you did it in reverse that works too..
glad it worked out for you
Please award accordingly :)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Amour22015Author Commented:
Great thanks your query gave what I was looking for I just had to reverse.....
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.