Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 != NOT EQUAL TO Query

Author  Topic 

jbulldog
Starting Member

21 Posts

Posted - 2012-10-26 : 22:36:36

I am trying to do a Not Equal To Query. I have multiple tables with numerous columns. All of the records needed are in two tables.
I am doing an INNER JOIN with a WHERE clause to filter for the records I need. I want to filter and list for the records that do not
have ' BENEFITS N/A' in the field(s) for the column Db.Services.Type.I'm trying to list records that have "missing data', ie data that's not in one of the field for that table columns, but should be.

Here are my Tables: Db.dbase and Db.Services

These are my Columns:
(Db.dbase.name, Db.dbase.ID_Num, Db.dbase.ID_Type,Db.dbase.GroupName, Db.dbase.Region, Db.dbase.Status, Db.Services.Type)

My Code on SQL Server 2008:

SELECT Db.dbase.name, Db.dbase.ID_Num, Db.dbase.ID_Type, Db.dbase.GroupName, Db.dbase.Region
FROM Db.dbase INNER JOIN Db.Services ON Db.dbase.ROW_ID = Db.Services.ROW_ID
WHERE Db.dbase.Region IN ('USA') AND (Db.dbase.Status = 'Active' OR dbo.Db.dbase.Status = 'Inactive') --AND
--Db.Services.Type != (' BENEFITS N/A')

Appreciate any help with proper code,format and some kinda resolution. Thanks in advance.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-10-26 : 23:36:45
sorry your requirement is fully clear. can you please give some sample data to illustrate it?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

bitsmed
Aged Yak Warrior

545 Posts

Posted - 2012-10-27 : 05:18:07
Try this:

select Db.dbase.name
,Db.dbase.ID_Num
,Db.dbase.ID_Type
,Db.dbase.GroupName
,Db.dbase.Region
from Db.dbase
where Db.dbase.Region in ('USA')
and Db.dbase.Status in ('Active','Inactive')
and not exist (select *
from Db.Services
where Db.Services.ROW_ID=Db.dbase.ROW_ID
and Db.Services.Type=(' BENEFITS N/A')
)
Go to Top of Page

jbulldog
Starting Member

21 Posts

Posted - 2012-10-27 : 19:53:27
Will try that bitsmed, it's a work thing so when I get back to the grind I'l check it out. As for sample data, since the data has to do with financial institutions I will give you mock data. What I am trying to return record wise is the name, ID number associated with a particular financial institution the benefits levels i.e. platinum, gold, silver and also tiers within each.

Each financial institution are in different global regions such as Latin America, Europe and Asia, etc. Each region has certain benefits common to all and other benefits associated with each level and each tier has or has not benefits depending on there level. Some levels that should have certain benefits don't.

This search is to determine which Institution levels tier is missing a particular benefit. Since All Institutions have benefits( different sets) searching for those would be fruitless.

The script I posted runs successfully but returns 0 results.

When I JOIN more tables it returns all the records for that region.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-10-27 : 21:34:44
so is the relationship between dbase and Services one to many

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -