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
 counting blanks

Author  Topic 

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 2008-07-02 : 05:09:22
I have this statement:

COUNT(SesTime)

when I check the tables, they're all blanks. Why are blanks being counted?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-02 : 05:19:27
is it blanks or space(' ')?. count ignores only NULL values.
Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 2008-07-02 : 05:22:54
it's blank
Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 2008-07-02 : 05:32:37
i got it..it's space (''). Is there a way to ignore the space when counting? thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-02 : 05:42:07
quote:
Originally posted by cutiebo2t

i got it..it's space (''). Is there a way to ignore the space when counting? thanks


try using a NULLIF inside

NULLIF(field,' ')
Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 2008-07-02 : 05:47:21
it's not actually Null. It's a space.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-07-02 : 08:59:03
quote:
Originally posted by cutiebo2t

i got it..it's space (''). Is there a way to ignore the space when counting? thanks


Add where clause

WHERE col>''

or

SELECT sum(case when col>'' then 1 else 0 end) as COUNTING from table

Madhivanan

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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-02 : 13:40:30
quote:
Originally posted by cutiebo2t

it's not actually Null. It's a space.


NULLIF(field,' ') will convert space to NULL
Go to Top of Page
   

- Advertisement -