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)
 Null Fields / Zero Values Problem

Author  Topic 

Jonny1409
Posting Yak Master

133 Posts

Posted - 2008-07-25 : 06:11:12
Hello,

I am having a problem with zero values, and I'm sure there is a simple way to fix it, but I don't know what it is.

Basically I have a view built up from a couple of other views.
Two of the fields (BookedDays and BookedHours) in my current view are showing as Null for certain employees (which is correct)

However, in order to use this view, I would like the Nulls to be 0 instead.

How can I do this ?

My view is :

SELECT dbo.tbl_EmployeeDetails.EmployeeNumber,
dbo.[vw_HolidaysBookedPerEE(Total)].BookedDays,
dbo.[vw_HolidaysBookedPerEE(Total)].BookedHours
FROM dbo.[vw_HolidaysBookedPerEE(Total)]
RIGHT OUTER JOIN dbo.tbl_EmployeeDetails ON dbo.[vw_HolidaysBookedPerEE(Total)].EmployeeNumber = dbo.tbl_EmployeeDetails.EmployeeNumber
LEFT OUTER JOIN dbo.[vw_ReserveHolidaysPerEE(Total)] ON
dbo.tbl_EmployeeDetails.EmployeeNumber = dbo.[vw_ReserveHolidaysPerEE(Total)].EmployeeNumber
LEFT OUTER JOIN dbo.[vw_FutureHolidaysPerEE(Total)] ON dbo.tbl_EmployeeDetails.EmployeeNumber = dbo.[vw_FutureHolidaysPerEE(Total)].EmployeeNumber

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-25 : 06:16:18
use isnull() or coalesce()

eg.
isnull(yourcol, 0)


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Jonny1409
Posting Yak Master

133 Posts

Posted - 2008-07-25 : 06:19:55
Where do I use this ? Do I simply add it to the SQL code ?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-25 : 06:24:54
[code]
dbo.tbl_EmployeeDetails.EmployeeNumber,
ISNULL(dbo.[vw_HolidaysBookedPerEE(Total)].BookedDays, 0) AS BookedDays,
. . .
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Jonny1409
Posting Yak Master

133 Posts

Posted - 2008-07-25 : 06:48:25
Thank you Khtan - that works a treat.

I really appreciate your help.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-25 : 07:03:24
refer this too:-
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/10/04/isnull-or-coalesce.aspx
Go to Top of Page
   

- Advertisement -