Hi allI'm trying to create a query to help with some calculations I'm running on some figures in a table. I've taken the logic from a calc function I previously built in VBA and tried to convert it over to TSQL but I'm having trouble.The code I'm using is as follows:CREATE FUNCTION SIMPLEINT (@x DATETIME, @prem MONEY)RETURNS MONEYASBEGIN DECLARE @y DATETIME DECLARE @simple MONEY DECLARE @rate15 DOUBLE DECLARE @rate8 DOUBLE SET @y = DATEADD(DAY, -(DAY(DATEADD(MONTH, 1, GETDATE()))),DATEADD(MONTH, 1, GETDATE())) SET @rate15 = 0.15 / 12 SET @rate8 = 0.08 / 12 WHILE @x <= @y BEGIN WHILE @x < '1993-01-04' BEGIN SET @simple = @simple + (@prem * @rate15) SET @x = DATEADD("M", 1, @x) END WHILE @x >= '1993-01-04' BEGIN SET @simple = @simple + (@prem * @rate8) SET @x = DATEADD("M", 1, @x) END ENDRETURN (@simple)ENDAnd the error it's returning is this:Msg 156, Level 15, State 1, Procedure SIMPLEINT, Line 11Incorrect syntax near the keyword 'DECLARE'.Msg 156, Level 15, State 1, Procedure SIMPLEINT, Line 13Incorrect syntax near the keyword 'SET'.Msg 137, Level 15, State 1, Procedure SIMPLEINT, Line 14Must declare the scalar variable "@rate15".Msg 137, Level 15, State 1, Procedure SIMPLEINT, Line 15Must declare the scalar variable "@rate8".Msg 137, Level 15, State 2, Procedure SIMPLEINT, Line 21Must declare the scalar variable "@rate15".Msg 137, Level 15, State 2, Procedure SIMPLEINT, Line 26Must declare the scalar variable "@rate8".
Can anyone tell me why my last declare and set statements aren't quite right? Thanks!