1

我正在尝试匹配此 SQL 语句上的 BETWEEN RANGE,如下所示:

( WAEXD8 BETWEEN &WAEXD8 AND &WAEXD8 ) 

上面的 SQL 语句适用于 DBS 数据源,虽然通过 ODBC 驱动程序对 iSeries 连接有效,但该 DB 连接类型不适用于 ADO.NET。ASP.NET ADO 连接需要将 BETWEEN RANGE 替换为以下语法

date(digits(FIELDNAME) CONCAT '000000') <= current date and date(digits(FIELDNAME) CONCAT '000000') >= current date 

WHERE FIELDNAME 是在原始 SQL 语句中找到的 WAEXD8 列...

我已经尝试过,但到目前为止还没有接近这个问题的真正解决方案......

同样,我希望将原始 SQL 查询的 ASP.NET C# 正则表达式匹配/替换为替换字符串,同时保留原始列名。这可能吗?我可以这样做的模式或模式示例是什么?

可能的其他解决方案:

匹配(任意数量的带有 BETWEEN 和 HTML 实体的空格&amp;

前任。:([(])|([BETWEEN])*([0-9A-Za-z])*([)])

4

1 回答 1

0

不完全确定你在追求什么,但这里有一些应该涵盖你的例子:

替换它们包含的所有 BETWEEN 语句&amp;和相同的 FIELDNAME

将匹配以下内容:

  • ( WAEXD8 BETWEEN &amp;WAEXD8 AND &amp;WAEXD8 )
  • (WAEXD8 BETWEEN &amp;WAEXD8 AND &amp;WAEXD8)
  • (WAEXD8 BETWEEN &amp;WAEXD8 AND &amp;WAEXD8 )
  • ( WAEXD8 BETWEEN &amp;WAEXD8 AND &amp;WAEXD8 )
  • ( FIELDEXAMPLE1 BETWEEN &amp;FIELDEXAMPLE1 AND &amp;FIELDEXAMPLE1 )

不匹配:

  • ( WAEXD8 BETWEEN WAEXD8 AND WAEXD8 )
  • ( WAEXD8 BETWEEN 0 AND 9000 )
  • ( WAEXD8 BETWEEN &amp;WAEXD8&A;NY1 AND &amp;WAEXD&8ANY2 )
  • ( FIELDEXAMPLE1 BETWEEN &amp;FIELDEXAMPLE2 AND &amp;FIELDEXAMPLE2 )


Regex regexObj = new Regex(@"\(\s*(\w+)\s+BETWEEN\s+&amp;\1\s+AND\s+&amp;\1\s*\)");
resultString = regexObj.Replace(subjectString, "(date(digits($1) CONCAT '000000') <= current date and date(digits($1) CONCAT '000000') >= current date)");

或者,如果您知道字段名称是AMAZINGFIELDNAME


Regex regexObj = new Regex(@"\(\s*(AMAZINGFIELDNAME)\s+BETWEEN\s+&amp;\1\s+AND\s+&amp;\1\s*\)");
resultString = regexObj.Replace(subjectString, "(date(digits($1) CONCAT '000000') <= current date and date(digits($1) CONCAT '000000') >= current date)");

用字符“&”和“;”替换所有 BETWEEN 语句,包括任何语句

将匹配以下内容:

  • ( WAEXD8 BETWEEN &amp;WAEXD8 AND &amp;WAEXD8 )
  • ( WAEXD8 BETWEEN &amp;WAEXD8&A;NY1 AND &amp;WAEXD&8ANY2 )
  • ( FIELDEXAMPLE1 BETWEEN &amp;FIELDEXAMPLE2 AND &amp;FIELDEXAMPLE2 )


Regex regexObj = new Regex(@"\(\s*(\w+)\s+BETWEEN\s+[\w&;]+\s+AND\s+[\w&;]+\s*\)");
resultString = regexObj.Replace(subjectString, "(date(digits($1) CONCAT '000000') <= current date and date(digits($1) CONCAT '000000') >= current date)");

于 2013-06-28T14:37:31.587 回答