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
 SQL Server Development (2000)
 move to nearest half hour

Author  Topic 

doran_doran
Posting Yak Master

179 Posts

Posted - 2008-06-02 : 17:25:43
Why this piece of code is not working? for example, i have 9.2223 and 234 in one column. it should be .5 and 4 hour. please suggest. I would truly appreciate it. I am working on a deadline and this took 4 hours from me. Please please please

alter Function oa.CalculateSplit(@idMinutes Float, @idCount Float) RETURNS Float
AS
BEGIN
DECLARE @ldMod Float,@ldMinSplit Float,@ldDecSplit Float

SET @ldMinSplit = @idMinutes / @idCount
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 / @idCount, 30)

END

doran_doran
Posting Yak Master

179 Posts

Posted - 2008-06-02 : 19:11:36
I am sure someone could help me. oh well, I really did NOT wanted my co-worker to help me. Here is the working version of the code.

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
Go to Top of Page
   

- Advertisement -