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
 Transact-SQL (2000)
 replacing NULL with 0

Author  Topic 

mike123
Master Smack Fu Yak Hacker

1462 Posts

Posted - 2004-11-03 : 18:50:05
Hi,

I'm running the following query but its breaking my code when NULL values are returned. How can modify this so that the columns "basic, grandfathered, and premium" return 0 ?

Thanks a bunch

Mike123




CREATE PROCEDURE dbo.select_AffiliateReport_Tier0_Total
(
@dateStart smalldatetime,
@dateEnd smalldatetime
)

AS SET NOCOUNT ON

SELECT
Count(*) as Signups,
SUM ( CASE WHEN mt.membershipTypeID = 1 THEN 1 ELSE 0 END ) as Basic,
SUM ( CASE WHEN mt.membershipTypeID = 2 THEN 1 ELSE 0 END ) as Grandfathered,
SUM ( CASE WHEN mt.membershipTypeID = 3 THEN 1 ELSE 0 END ) as Premium1

FROM
tblUserDetails ud
INNER JOIN tblMemberships mem ON mem.purchasedFor = ud.UserID
INNER JOIN tblMembershipTypes mt ON mt.membershipTypeId = mem.membershipTypeId

WHERE
mem.[dateStart] BETWEEN @dateStart AND @dateEnd



GO


rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2004-11-03 : 18:55:16
Couldn't you just use COALESCE or ISNULL around the sum aggregates ?

rockmoose
Go to Top of Page

mike123
Master Smack Fu Yak Hacker

1462 Posts

Posted - 2004-11-03 : 19:09:36
i was getting an error before and thought I couldnt on the SUM for some reason iooops....... thanks I fixed it now

cheers
mike123
Go to Top of Page
   

- Advertisement -