SQLTeam.com | Weblogs | Forums

T-SQL Query Help


#1

Hi,

--Create Test Table
CREATE TABLE [dbo].[Null_Table](
[CID] [int] NULL,
[MID] [int] NULL
) ON [PRIMARY]

--Insert Sample Data
insert into Null_Table(CID,MID)
valueS (123,456)
insert into Null_Table(CID,MID)
valueS (123,Null)
insert into Null_Table(CID,MID)
valueS (123,0)

select * from Null_Table--Should be 3 Records.

SELECT * FROM Null_Table
WHERE CID IS NOT NULL
AND MID IS NOT NULL

Note:- Please help me to understand, I should receive 3 records after I run the final query, why I am getting 2 records. Please help me to understand.
Thank You.


#2

Why do you think you should get three results when you are not pulling data with NULL for MID?


#3

Maybe you want OR instead of AND:

WHERE CID IS NOT NULL
OR MID IS NOT NULL