0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

五月雨のユーザ定義関数(WHERE文のリテラルを変数置換)

Last updated at Posted at 2025-05-09
Function ReplaceWhereLiterals(sqlText As String) As String
    Dim reg As Object
    Set reg = CreateObject("VBScript.RegExp")
    
    reg.IgnoreCase = True
    reg.Global = True
    ' 1: WHERE/AND/OR
    ' 2: 空白
    ' 3: カラム名
    ' 4: 演算子 (=, <>, <=, >=, <, >)
    ' 5: リテラル値(シングルクォート付き文字列/数値/英数字/その他)
    reg.Pattern = "(WHERE|AND|OR)(\s+)([A-Za-z_][A-Za-z0-9_]*?)\s*(=|<>|<=|>=|<|>)\s*('[^']*'|\d+|[A-Za-z0-9]+|[^\s\)\(]+)"
    
    ' 置換: 「WHERE カラム 演算子 リテラル」→「WHERE カラム 演算子 [カラム]」
    ReplaceWhereLiterals = reg.Replace(sqlText, "$1$2$3$4[$3]")
End Function
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?