codice:
Function codiceSottoConto(id As Long) As String
    rsSottoConti.Open "select * from sottoconti WHERE id = " & id, db, adOpenStatic, adLockReadOnly
    If Not rsSottoConti.EOF Then
        rsConti.Open "select * from conti WHERE id = " & rsSottoConti("idconto"), db, adOpenStatic, adLockReadOnly
        If Not rsConti.EOF Then
            rsGruppi.Open "select * from gruppi WHERE id = " & rsConti("idGruppo"), db, adOpenStatic, adLockReadOnly
            If Not rsGruppi.EOF Then
                rsStati.Open "select * from stati WHERE id = " & rsGruppi("idStato"), db, adOpenStatic, adLockReadOnly
                If Not rsStati.EOF Then
                    codiceSottoConto = rsStati("codice") & "." & rsGruppi("codice") & "." & rsConti("codice") & "." & rsSottoConti("codice")
                End If
            End If
        End If
    End If
end function
si può convertire in una funzione/procedure di sql server?