Hi all,
I'm very new to SQL server and I'm trying to get started by translating some fairly simple functions in Access to SQL Server 2000 for performance reasons.
Here's a good example. I'm calculating the "Return on Investment" for cashflows from a DB in Access I embed the function call (GetROI) in the Query like so:
SELECT FundPerformance.Fund_ID, FundPerformance.Date, getROI([date],[fund_id]) AS ROI, FROM FundPerformance
WHERE (((FundPerformance.Subscriptions)>0));
The Function is as follows:
Function getROI(ByVal aDate As Date, ByVal FundID As String) As Double
On Error Resume Next
Dim sql As String
Dim rs As Recordset
Dim ROI As Double
SELECT FundPerformance.Fund_ID, FundPerformance.Date, getROI([date],[fund_id]) AS ROI, FROM FundPerformance
WHERE (((FundPerformance.Subscriptions)>0));
Function getROI(ByVal aDate As Date, ByVal FundID As String, PGAFUND As String) As Double
On Error Resume Next
Dim sql As String
Dim rs As Recordset
Dim ROI As Double
sql = "Select [MTD ROR], Fund_ID, Date From fundPerformance where (Fund_id like '" & Replace(FundID, "'", "''") & "') AND (Date >= #" & Replace(aDate, "'", "''") & "#) ORDER BY FundPerformance.Date;"
Set rs = CurrentDb.OpenRecordset(sql)
rs.MoveFirst
ROI = rs.Fields(0)
rs.MoveNext
While Not rs.EOF
ROI = ((1 + ROI) * (1 + rs.Fields(0)) - 1)
rs.MoveNext
Wend
getROI = ROI
Set rs = Nothing
End Function
This returns a double (ROI) in each row of the query. What would be the best way to go about doing this on a SQL Server?
I think one good example of this sort of thing and I'll be fine, I'm just having trouble finding any examples of something similar.
I'm very new to SQL server and I'm trying to get started by translating some fairly simple functions in Access to SQL Server 2000 for performance reasons.
Here's a good example. I'm calculating the "Return on Investment" for cashflows from a DB in Access I embed the function call (GetROI) in the Query like so:
SELECT FundPerformance.Fund_ID, FundPerformance.Date, getROI([date],[fund_id]) AS ROI, FROM FundPerformance
WHERE (((FundPerformance.Subscriptions)>0));
The Function is as follows:
Function getROI(ByVal aDate As Date, ByVal FundID As String) As Double
On Error Resume Next
Dim sql As String
Dim rs As Recordset
Dim ROI As Double
SELECT FundPerformance.Fund_ID, FundPerformance.Date, getROI([date],[fund_id]) AS ROI, FROM FundPerformance
WHERE (((FundPerformance.Subscriptions)>0));
Function getROI(ByVal aDate As Date, ByVal FundID As String, PGAFUND As String) As Double
On Error Resume Next
Dim sql As String
Dim rs As Recordset
Dim ROI As Double
sql = "Select [MTD ROR], Fund_ID, Date From fundPerformance where (Fund_id like '" & Replace(FundID, "'", "''") & "') AND (Date >= #" & Replace(aDate, "'", "''") & "#) ORDER BY FundPerformance.Date;"
Set rs = CurrentDb.OpenRecordset(sql)
rs.MoveFirst
ROI = rs.Fields(0)
rs.MoveNext
While Not rs.EOF
ROI = ((1 + ROI) * (1 + rs.Fields(0)) - 1)
rs.MoveNext
Wend
getROI = ROI
Set rs = Nothing
End Function
This returns a double (ROI) in each row of the query. What would be the best way to go about doing this on a SQL Server?
I think one good example of this sort of thing and I'll be fine, I'm just having trouble finding any examples of something similar.