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)
 help with Isnull(,)

Author  Topic 

mike123
Master Smack Fu Yak Hacker

1462 Posts

Posted - 2007-04-04 : 23:33:57
Hi,

I've used ISNULL before, but can't seem to figure out how to place it in this query.

Can anyone lend a hand?

Thanks very much!!


SELECT

SUM ( CASE WHEN points = 10 THEN 1 ELSE 0 END ) as '10',
SUM ( CASE WHEN points = 20 THEN 1 ELSE 0 END ) as '20',
SUM ( CASE WHEN points = 30 THEN 1 ELSE 0 END ) as '30',
SUM ( CASE WHEN points = 40 THEN 1 ELSE 0 END ) as '40',
SUM ( CASE WHEN points = 50 THEN 1 ELSE 0 END ) as '50',
SUM ( CASE WHEN points = 60 THEN 1 ELSE 0 END ) as '60',
SUM ( CASE WHEN points = 70 THEN 1 ELSE 0 END ) as '70',
SUM ( CASE WHEN points = 80 THEN 1 ELSE 0 END ) as '80',
SUM ( CASE WHEN points = 90 THEN 1 ELSE 0 END ) as '90',
SUM ( CASE WHEN points = 100 THEN 1 ELSE 0 END ) as '100',

COUNT(*) AS TotalVotes FROM tblRandomVote

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-04-04 : 23:42:58
ISNULL on which column ? points ? You have taken care of it with CASE WHEN . . END



KH

Go to Top of Page

mike123
Master Smack Fu Yak Hacker

1462 Posts

Posted - 2007-04-04 : 23:49:01

Sorry for forgetting that information.

I want to make sure I don't bring back any records with a NULL value.

Currently the data brought back looks like this

10,20,30,40,50,60,70,80,90,100,totalVotes
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0

Thanks again!
mike123
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-04-05 : 00:12:18
[code]
isnull( SUM ( CASE WHEN points = 10 THEN 1 ELSE 0 END ) , 0)
[/code]


KH

Go to Top of Page

mike123
Master Smack Fu Yak Hacker

1462 Posts

Posted - 2007-04-05 : 00:17:37
I swore i tried that

oh well, this worked perfectly!!

thanks very much
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-04-05 : 01:01:48
or use coalesce in place of ISNULL

Madhivanan

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

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-04-05 : 03:59:10
+1 for Coalesce() over IsNull()...especially since I read the post by Seventhnight !

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -