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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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

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

Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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

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
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.
plusone3055Commented:
okay im sure we can resolve :)

Please paste in which query you used
and I will alter
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
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

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.
plusone3055Commented:
you did it in reverse that works too..
glad it worked out for you
Please award accordingly :)

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