I have an MS Access user defined function that I must recreate in SQL Server.
Public Function durCalc(projNum As String, changeDt As Date) As Integer
Dim calcDur As Integer
'gchangeDt and gprojNum are global variables whose value
'come from the previous record
durCalc = 0
If projNum = gprojNum Then
calcDur = changeDt - gchangeDt
gchangeDt = changeDt
durCalc = calcDur
Else
gchangeDt = changeDt
gprojNum = projNum
durCalc = 0
End If
This function would be called from within a stored procedure inside a SQL statement.
The MS Access SQL statement is as follows:
SELECT t_milestoneSchedule.[JDE Proj Num], Max((durCalc([JDE Proj Num],[Date]))) AS changeDuratin
FROM t_milestoneSchedule
WHERE (((t_milestoneSchedule.Date) Is Not Null) AND ((t_milestoneSchedule.[Milestone ID])="700") AND ((t_milestoneSchedule.[P/A])="P"))
GROUP BY t_milestoneSchedule.[JDE Proj Num]
ORDER BY t_milestoneSchedule.[JDE Proj Num], Last(t_milestoneSchedule.DateStamp);
Again, this will need to get converted from MS Access to a SQL Stored procedure?
Do I need to use a cursor since my durCalc depends on the paramters of the previous record?
How do I declare a memory variable to be global like in access.
Public Function durCalc(projNum As String, changeDt As Date) As Integer
Dim calcDur As Integer
'gchangeDt and gprojNum are global variables whose value
'come from the previous record
durCalc = 0
If projNum = gprojNum Then
calcDur = changeDt - gchangeDt
gchangeDt = changeDt
durCalc = calcDur
Else
gchangeDt = changeDt
gprojNum = projNum
durCalc = 0
End If
This function would be called from within a stored procedure inside a SQL statement.
The MS Access SQL statement is as follows:
SELECT t_milestoneSchedule.[JDE Proj Num], Max((durCalc([JDE Proj Num],[Date]))) AS changeDuratin
FROM t_milestoneSchedule
WHERE (((t_milestoneSchedule.Date) Is Not Null) AND ((t_milestoneSchedule.[Milestone ID])="700") AND ((t_milestoneSchedule.[P/A])="P"))
GROUP BY t_milestoneSchedule.[JDE Proj Num]
ORDER BY t_milestoneSchedule.[JDE Proj Num], Last(t_milestoneSchedule.DateStamp);
Again, this will need to get converted from MS Access to a SQL Stored procedure?
Do I need to use a cursor since my durCalc depends on the paramters of the previous record?
How do I declare a memory variable to be global like in access.