by Manjunath MS (1 Submission)
Category: String Manipulation
Compatability: Visual Basic 4.0 (32-bit)
Difficulty: Unknown Difficulty
Originally Published: Fri 18th October 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Function returns the formated string which can be used for SQL Server
' 1. strSQLString -> String which has to be formated for SQL
' 2. boolIsName -> Optional. Signifies whether the String passed is a name in SQL or Not
' Function returns the formated string which can be used for SQL Server
' All the characters which are not allowed in Naming the Object in SQL Server
' is removed from the passed string
' The invalid characted for naming are put in a
' constant cnstInValidChars each seperated by a #(Hash)
Private Function CorrectString(strSQLString As String, Optional boolIsName As Boolean) As String
' As specified in SQL
'Const cnstInValidChars = " #*#[#]#\#|#?#<#>#:#""#?#%#."
' As specified in SQL and Some More
Const cnstInValidChars = " #,#--#.#+#-#/#\#|#*#>#<#&#^#(#)#[#]#{#}#:#;#?#~#`#'#!#%#=#"""
Dim strSQL As String
Dim arrChar() As String
Dim intCntr As Integer
strSQL = Replace$(strSQLString, "'", "''", , , vbTextCompare)
' Formating for Object Name
If boolIsName Then
arrChar() = Split(cnstInValidChars, "#", , vbTextCompare)
For intCntr = 0 To UBound(arrChar)
strSQL = Replace$(strSQL, arrChar(intCntr), "", , , vbTextCompare)
Next intCntr
End If
CorrectString = strSQL
End Function
No comments have been posted about Function returns the formated string which can be used for SQL Server. Why not be the first to post a comment about Function returns the formated string which can be used for SQL Server.