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 2000 Forums
 SQL Server Development (2000)
 Select Statement

Author  Topic 

Steve2106
Posting Yak Master

183 Posts

Posted - 2009-03-06 : 19:46:01
Hi There,

Can someone help please.

I want to select all records from my table where the column completionDate = 0 or = null.
How would I code that.

I have tried:
SELECT * FROM MyTable where MyTable.CompDate = 0
But this sometimes throws an error because the column is null and not 0. How would I check if it's not 0 or null.

Thaks for your help,

Steve.


Steve

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-03-06 : 20:16:12
SELECT * FROM MyTable
where ISNULL(MyTable.CompDate,0) = 0
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-03-06 : 20:28:40

What datatype is CompDate?

SELECT * FROM MyTable Where CompDate = 0 or CompDate is null

Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-03-06 : 23:56:07
SELECT * FROM MyTable
where coalesce(CompDate,0) = 0
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-03-07 : 02:26:14
Avoid using functions over column names.They will prevent sql server from using index if defined. Use Sodeep's approach


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Steve2106
Posting Yak Master

183 Posts

Posted - 2009-03-07 : 16:41:46
Hi Guys,

Thanks for all the help, I appreciate it.

Best Regards,



Steve
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-08 : 13:01:53
quote:
Originally posted by Steve2106

Hi Guys,

Thanks for all the help, I appreciate it.

Best Regards,



Steve


=null wont work under default settings as NULL is not stored as a value. For considering NULL as a value you need to change ANSI NULL setting
Go to Top of Page

tosscrosby
Aged Yak Warrior

676 Posts

Posted - 2009-03-10 : 17:17:12
quote:
Originally posted by Steve2106

Hi Guys,
Thanks for all the help, I appreciate it.
Best Regards,
Steve



And your solution was???? Always help out the next poster whenever possible.

Terry

-- Procrastinate now!
Go to Top of Page
   

- Advertisement -