By using expertatexcel.com you agree to our cookie policy, We and our partners operate globally and use cookies, for multiple purposes

Become an Σxpert at Σxcel.com

 


RemoveSQLComments - udf

Function RemoveSQLComments(sSQL) as string

'This function will remove /*   from passed sql

lPtr = instr(sSQL,"/*"
If lPtr > 0 Then
    'continue
Else
    RemoveSQLComments = sSQL
    Exit Function
End If

sFixed = sSQL

Do Wile lPtr > 0
    lEndComment = InStr(lPtr, sFixed, "")
    if lEndComment = 0 Then
        Msgbox " invalid SQL, opening comment no closing"
    end if
    sFixed = left(sFixed, lPtr - 1) & " " & Mid(sFixed, lEndComment +2)

    lPtr = InStr(lPtr, sFiexed, "/*")

Loop

'Remove end characters that aren't needed and cause issues
for i = Len(sFixed) to 1 step -1
    sChar = Mid(sFixed, i, 1)
    If sChar = " " Or sChar = vbCR or sChar = vbLF Then
    Else
        Exit For
    End if

Next

sFixed = Mid(sFixed, 1, i)

RemoveSQLComments = sFixed

End Function