TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Istudent Rana
1.4k
342
84k
how do i return 0 from function when query return no record
Oct 12 2018 11:05 AM
I have a function which return total hours worked. But in some cases there will be no entry at all. In that case select query return empty records. I would like to return 0 if there is no record. How do i achieve this?
ALTER FUNCTION [dbo].[ufnGetTotalHoursWorked](@id int)
RETURNS decimal(18,2)
AS
BEGIN
DECLARE @workedHours decimal(18,2);
SELECT @workedHours = (SELECT Sum(WorkedHours) FROM [WorkedHours] WHERE EmployeeId = @id GROUP BY EmployeeId having EmployeeId=@id)
RETURN @workedHours;
END
Reply
Answers (
1
)
A JOB error..SQL SERVER MANAGMENT STUDIO 2012
Pass multiple values in single parameter -Procedure