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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Where flied is not null case

Author  Topic 

ismailc
Constraint Violating Yak Guru

290 Posts

Posted - 2010-02-28 : 06:37:47
Good day,

I'm struggling to remove null rows dependant on a certain criteria in my where clause

I want remove null only when the VStatus is not "Open"
I have done a few where case but not where is not null then do nothing

eg: where ..
and DisplayName <>(case when EventID='390' then 'Site' else '1' end)

but to remove nulls:
and DisplayName is not (case when VStatus<>'Open' and DisplayName is null then Null else ? end)

Not to sure how as i tried a few things
else "1") - but
i Also get error incorrect syntax at is not

Please help

ismailc
Constraint Violating Yak Guru

290 Posts

Posted - 2010-02-28 : 07:37:29
I got help :)

WHERE 1 = (CASE WHEN vStatus <> 'Open' AND DisplayName IS NULL THEN 0 ELSE 1 END)
Go to Top of Page

DBA in the making
Aged Yak Warrior

638 Posts

Posted - 2010-02-28 : 07:55:48
You could do the same thing with:

WHERE vStatus = 'Open'
OR DisplayName IS NOT NULL

That seems much simpler to me.

There are 10 types of people in the world, those that understand binary, and those that don't.
Go to Top of Page
   

- Advertisement -