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
 Express Edition and Compact Edition (2005)
 make a sum of values without the ISNULL function

Author  Topic 

lizzie88
Starting Member

2 Posts

Posted - 2010-11-19 : 13:53:02
Hi,

this is the first time I'm posting on this forum but I am stuck with a silly problem.

I have rows which have columns in integer format. I need to get the total into a new column. My problem is that there is no ISNULL in SQL CE so I tried something like

(CASE WHEN [Courtesy] IS NULL
THEN 0
ELSE [Courtesy] AS Col1) +
(CASE WHEN [PositiveAttitude] IS NULL
THEN 0
ELSE [PositiveAttitude] AS Col2)
AS SUMValues

I only get the error saying that there was a problem parsing the query in SQL CE or Oncorrect syntax near the word AS in SQL Server. I don't know how to set it to 0 if it's null without using the ISNULL function. Unfortunatelly I can't set the default value to 0 in order to always have a non null value.

Thanks for your help.

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-11-19 : 14:01:18
you're missing the END keyword to your case ststements.

SELECT CASE WHEN [Courtesy] IS NULL
THEN 0
ELSE [Courtesy]
END
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-11-19 : 14:02:11
is COALESCE function available in CE?

checked...it is. use that.

http://msdn.microsoft.com/en-us/library/ms174075(SQL.90).aspx
Go to Top of Page

lizzie88
Starting Member

2 Posts

Posted - 2010-11-19 : 14:09:42
I am so ashamed about the mising END. I will give a try the coalesce as well but it seems to be working

Thanks both of you
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-11-19 : 15:18:22
you're welcome, from both of us
Go to Top of Page
   

- Advertisement -