Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

User Defined Function and Processing the next record

Status
Not open for further replies.

ibethea

MIS
Feb 8, 2002
20
US
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.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top