By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,378 Members | 1,286 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,378 IT Pros & Developers. It's quick & easy.

Round Function

100+
P: 145
I am trying to import two functions from MS-ACCESS to sql server 2000. Can anything shed some lights please.....................

create Function CalculateSplit(ByVal idMinutes As Double, ByVal ilCount As Double) As Double
Dim ldMod As Double
Dim ldMinSplit As Double
Dim ldDecSplit As Double
--Debug.Print ldMod
ldMinSplit = idMinutes / ilCount
ldMod = ldMinSplit Mod 15
ldDecSplit = (ldMinSplit - Int(ldMinSplit))
If (ldDecSplit <= 0.5) Then
ldMod = ldMod + ldDecSplit
Else
ldMod = ldMod - 1 + ldDecSplit
End If

--CalculateSplit = Round(((idMinutes / ilCount) + IIf(((idMinutes / ilCount) Mod 15) = 0, 0, (15 - ldMod))) / 60, 2)
CalculateSplit = RoundUp(idMinutes / ilCount, 30)

End Function

CREATE Function RoundUp(ByVal idMinutes As Double, ByVal id As Double) As Double

Dim ldMod As Double
Dim ldMinSplit As Double
Dim ldDecSplit As Double
--Debug.Print ldMod

ldMod = idMinutes Mod id
ldDecSplit = (idMinutes - Int(idMinutes))
If (ldDecSplit <= 0.5) Then
ldMod = ldMod + ldDecSplit
Else
ldMod = ldMod - 1 + ldDecSplit
End If

RoundUp = Round(((idMinutes) + IIf(((idMinutes) Mod id) = 0, 0, (id - ldMod))) / 60, 2)

End Function
Jun 2 '08 #1
Share this Question
Share on Google+
4 Replies


100+
P: 145
I hardly get any response from bytes's forums. Are these forums active? I mean are there real developers subscribe to this site? hmm...
Jun 2 '08 #2

ck9663
Expert 2.5K+
P: 2,878
The forum will not send you email if someone replied to you. You have to come back to check your posts.

About your question, have you tried the ROUND() built-in function of MS-SQL?

-- CK
Jun 2 '08 #3

100+
P: 145
alter Function oa.CalculateSplit(@idMinutes Float, @ilCount Float) RETURNS Float
AS
BEGIN
DECLARE @ldMod Float,@ldMinSplit Float,@ldDecSplit Float

SET @ldMinSplit = @idMinutes / @ilCount
SET @ldMod = cast(@ldMinSplit as int)% 15
SET @ldDecSplit = @ldMinSplit - CAST(@ldMinSplit AS int)

SET @ldMod =CASE WHEN @ldDecSplit <= 0.5 THEN @ldMod + @ldDecSplit
ELSE @ldMod - 1 + @ldDecSplit
END
RETURN Round(@idMinutes / @ilCount, 60)
END

This is not replacing my original roundup and calculatesplit function. please suggest.
Jun 2 '08 #4

100+
P: 145
This is the working code. THIS FORUM IS NO GOOD. HARDLY ANY HELP IS RECEIVED.

alter Function oa.CalculateSplit(@idMinutes Float, @idCount Float) RETURNS Float
AS
BEGIN

RETURN oa.Roundup(@idminutes/@idcount)

END

alter Function oa.RoundUp(@idMinutes As float) returns float
as
begin
declare @hours as float
set @hours = CAST(@idminutes AS INT)

IF @idminutes-@hours > 0
if @idminutes-@hours > .5
set @hours = @hours+1
ELSE
SET @HOURS=@HOURS+.5
return @HOURS
End
Jun 2 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.