Hi,
I want to use a stored procedure for my dataset, but I need to do some calculations for the returned results.
How do I go about converting VBA logic into T-SQL UDF's and is this possible?
For example how would you write the following using a T-SQL Scalar UDF?
Basically I need to check for each record in my recordset, if there are any references and if they are OK. the returned value needs to be a simple varchar(3) string of either 'Yes' or 'No'.
Is this possible?
Or would I be better running the SP, getting the record set, looping it and doing the calculation from within VBA?
Thanks,
1DMF
"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."
"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Dance Music Downloads
I want to use a stored procedure for my dataset, but I need to do some calculations for the returned results.
How do I go about converting VBA logic into T-SQL UDF's and is this possible?
For example how would you write the following using a T-SQL Scalar UDF?
Code:
Public Function CheckRefs(ByVal iContactID As Integer) As String
' routine to check if references present and OK
CheckRefs = "Yes"
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("SELECT Applied,Received,Acceptable FROM References WHERE ContactID = " & iContactID)
If rs.RecordCount = 0 Then
CheckRefs = "No"
Else
Do While Not rs.EOF
If Nz(rs.Fields("Applied"), "") = "" Or Nz(rs.Fields("Received"), "") = "" Or Nz(rs.Fields("Acceptable"), "No") = "No" Then
CheckRefs = "No"
rs.MoveLast
End If
rs.MoveNext
Loop
End If
Set rs = Nothing
End Function
Basically I need to check for each record in my recordset, if there are any references and if they are OK. the returned value needs to be a simple varchar(3) string of either 'Yes' or 'No'.
Is this possible?
Or would I be better running the SP, getting the record set, looping it and doing the calculation from within VBA?
Thanks,
1DMF
"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."
"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Dance Music Downloads