Link to home
Start Free TrialLog in
Avatar of OxonDev
OxonDevFlag for United Kingdom of Great Britain and Northern Ireland

asked on

VB Function to UDF

Hi all, I'm looking for a UDF equivalent in SQL Server 2000 for this VB/VBA function.  
Public Function ConcatString(ByVal Seperator As String, ParamArray StringValues() As Variant) As String
'---------------------------------------
'|Concatonate elements in passed array.|
'---------------------------------------
On Error GoTo Err_ConcatString
Dim varValue As Variant
Dim strOutput As String
    
    If Not IsArray(StringValues) Then GoTo Exit_ConcatString
    
'Loop thru' array evaluating array members and adding valid members to output string.
    For Each varValue In StringValues
        varValue = Nz(varValue, "")
        Do Until varValue = Replace(varValue, "  ", "")
            varValue = Replace(varValue, "  ", "")
        Loop
        If Not varValue = "" Then
            If Not strOutput = "" Then
                strOutput = strOutput & Seperator
            End If
            strOutput = strOutput & varValue
        End If
    Next varValue
    
'Return function value.
    ConcatString = strOutput
  
Exit_ConcatString:
    Exit Function
  
Err_ConcatString:
    MsgBox "Err_ConcatString " & Err.Number & ": " & Err.Description
    Resume Exit_ConcatString
End Function

Open in new window

Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

>ParamArray StringValues()
as sql server does not have this concept of a paramarray, you cannot really replicate this vb function into a udf.
Avatar of OxonDev

ASKER

Hi angellll.  I'll settle for say passing a maximum of say 20 varchar parameter after the seperator parameter, it's the internals that are frustrating me...
as a function cannot have optional parameters, you will have to pass NULLs for example for all the parameters that are "unused" on every call.

apart from that:
what is the "usage" of this function? I mean, where does the "data" come for this function calling?
Avatar of OxonDev

ASKER

Rats I'd forgotten it doesn't act like a stored procedure.  The function was intended to be a catch all concat function as it is in VB.  Any suggestions?
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial