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.
Author |
Topic |
doran_doran
Posting Yak Master
179 Posts |
Posted - 2008-06-02 : 14:53:06
|
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 DoubleDim ldMod As DoubleDim ldMinSplit As DoubleDim ldDecSplit As Double--Debug.Print ldModldMinSplit = idMinutes / ilCountldMod = ldMinSplit Mod 15ldDecSplit = (ldMinSplit - Int(ldMinSplit))If (ldDecSplit <= 0.5) ThenldMod = ldMod + ldDecSplitElseldMod = ldMod - 1 + ldDecSplitEnd If--CalculateSplit = Round(((idMinutes / ilCount) + IIf(((idMinutes / ilCount) Mod 15) = 0, 0, (15 - ldMod))) / 60, 2)CalculateSplit = RoundUp(idMinutes / ilCount, 30)End FunctionCREATE Function RoundUp(ByVal idMinutes As Double, ByVal id As Double) As DoubleDim ldMod As DoubleDim ldMinSplit As DoubleDim ldDecSplit As Double--Debug.Print ldModldMod = idMinutes Mod idldDecSplit = (idMinutes - Int(idMinutes))If (ldDecSplit <= 0.5) ThenldMod = ldMod + ldDecSplitElseldMod = ldMod - 1 + ldDecSplitEnd IfRoundUp = Round(((idMinutes) + IIf(((idMinutes) Mod id) = 0, 0, (id - ldMod))) / 60, 2)End Function |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-02 : 15:05:55
|
Use CASE WHEN instead of IIF and also use CAST(field as int) instead of int(field). Also syntax of Round is ROUND(field,precision) |
 |
|
doran_doran
Posting Yak Master
179 Posts |
Posted - 2008-06-02 : 15:10:08
|
Thank you Vikas for your input. I am totally new to sql server function. Can you please try to convert one of the function so I can use that as a sample and write the other one. I would truly appreciated it.I am logged in as "oa". is that same as schema? |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-02 : 15:17:34
|
Something like this:-create Function CalculateSplit(idMinutes Float, ilCount Float) RETURNS Float ASBEGINDECLARE @ldMod Float,@ldMinSplit Float,@ldDecSplit FloatSET @ldMinSplit = @idMinutes / @ilCountSET @ldMod = @ldMinSplit % 15SET @ldDecSplit = @ldMinSplit - CAST(@ldMinSplit AS int)SET @ldMod =CASE WHEN @ldDecSplit <= 0.5 THEN @ldMod + @ldDecSplit ELSE @ldMod - 1 + @ldDecSplit ENDRETURN Round(@idMinutes / @ilCount, 30)END |
 |
|
doran_doran
Posting Yak Master
179 Posts |
Posted - 2008-06-02 : 15:25:07
|
hi Visakh,Thank you very very much for your valuable time. I ran the function you supplied. 1. I am receiving following error. 2. Does your function takes care of roundup (the sub function) within.ThanksJuliaerror Msg 170, Level 15, State 1, Procedure CalculateSplit, Line 2Line 2: Incorrect syntax near 'idMinutes'.Msg 137, Level 15, State 2, Procedure CalculateSplit, Line 9Must declare the variable '@idMinutes'.Msg 137, Level 15, State 2, Procedure CalculateSplit, Line 16Must declare the variable '@idMinutes'. |
 |
|
doran_doran
Posting Yak Master
179 Posts |
Posted - 2008-06-02 : 16:22:21
|
I fixed idmod but function has no error. but I am not able to accomplish what I had planned. Please suggest.ThanksJuliaCREATE Function oa.CalculateSplit(@idMinutes Float, @ilCount Float) RETURNS Float ASBEGINDECLARE @ldMod Float,@ldMinSplit Float,@ldDecSplit FloatSET @ldMinSplit = @idMinutes / @ilCountSET @ldMod = cast(@ldMinSplit as int)% 15SET @ldDecSplit = @ldMinSplit - CAST(@ldMinSplit AS int)SET @ldMod =CASE WHEN @ldDecSplit <= 0.5 THEN @ldMod + @ldDecSplit ELSE @ldMod - 1 + @ldDecSplit ENDRETURN Round(@idMinutes / @ilCount, 30)END |
 |
|
doran_doran
Posting Yak Master
179 Posts |
Posted - 2008-06-02 : 19:12:00
|
This code is working..alter Function oa.CalculateSplit(@idMinutes Float, @idCount Float) RETURNS Float ASBEGINRETURN oa.Roundup(@idminutes/@idcount) ENDalter Function oa.RoundUp(@idMinutes As float) returns floatasbegin declare @hours as floatset @hours = CAST(@idminutes AS INT)IF @idminutes-@hours > 0 if @idminutes-@hours > .5 set @hours = @hours+1 ELSE SET @HOURS=@HOURS+.5return @HOURSEnd |
 |
|
|
|
|
|
|