Touchy Vivace
Touchy Vivace

Reputation: 103

How can I use where with two condition

I have 2 columns:

  1. CategoryID
  2. Name

How can I use where if name only in a CategoryID = 1 and has a NULL value it will not show.

where not (name IS NULL or categoryID = 1) 

I tried this but it's not working.

Upvotes: 1

Views: 54

Answers (3)

Touchy Vivace
Touchy Vivace

Reputation: 103

I combined both of your suggestion and It's work !

  WHERE ((t.STDName Is not Null)OR( t.ID != 1))

like this Thank you very much

Upvotes: 0

J0e3gan
J0e3gan

Reputation: 8938

Since you indicated that records should not be displayed when "name only in a CategoryID = 1 and has a NULL value", try this:

WHERE CategoryID <> 1 OR
      (CategoryID = 1 AND Name IS NOT NULL)

This will display records with any CategoryID, just not records where CategoryID = 1 and Name IS NULL.

Upvotes: 1

Ross Bush
Ross Bush

Reputation: 15175

If you are asking where name is not null and the categoryID is 1 then this will work.

where (NOT name IS NULL AND categoryID = 1)

Upvotes: 0

Related Questions