Stored Procedure for Decimal Point Customization

ALTER function [dbo].[fn_TwoDigitAfterDecimalPoint]
(
@MainInput money
)
--select dbo.fn_TwoDigitAfterDecimalPoint('2222.0000')
returns varchar(50)
as
begin
declare @returnValue varchar(20),
@Id int
set @Id = 0
SET @Id = CHARINDEX('.',@MainInput)
IF @Id != 0
SET @returnValue = LEFT(@MainInput,@Id + 2)
return @returnValue
end

USE:

ALTER PROCEDURE [dbo].[sp_ReviewResult]
(
@TermId varchar(50),
@CourseId varchar(50)
)
AS
BEGIN
SELECT DISTINCT StudentId, TermId, CourseId, Attendance, SectionA, SectionB,
dbo.fn_ReturnMarks(@TermId,@CourseId, StudentId) AS TotalClassTest,
(Attendance+ SectionA + SectionB + dbo.fn_ReturnMarks(@TermId,@CourseId, StudentId)+Grace) AS Total,
[dbo].[fn_TwoDigitAfterDecimalPoint]((Attendance+ SectionA + SectionB + dbo.fn_ReturnMarks(@TermId,@CourseId, StudentId)+Grace)/3) AS PercentTotal,
Grace
FROM T_Term_Std_Result_Theory_Details
WHERE TermId=@TermId AND CourseId=@CourseId
END

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s