如下的一个复合sql语句, 要获得一个不被()括起来的 where
String sql= " select a.*,b.* ,c.* , a.zl || a.hm as zlhm,
(select top 1 kindname from codetable1 where t1.xh= a.xh and t1.xh like '10%') as knamefrom table1 a, table2 b , table3 c where ( a.area = b.area or a.area= c.area ) and a.city = c.city "如上,如果有这样的where ,就 将这个where 之后的内容 前后加上括号和自己写的一段内容,即效果如下
... where ( ( a.area = b.area or a.area= c.area ) and a.city = c.city ) and 1=2
然后返回这个被变动过的sql如果找不到这样的where 就返回"".
很实用的,在线欢迎拍砖
String sql= " select a.*,b.* ,c.* , a.zl || a.hm as zlhm,
(select top 1 kindname from codetable1 where t1.xh= a.xh and t1.xh like '10%') as knamefrom table1 a, table2 b , table3 c where ( a.area = b.area or a.area= c.area ) and a.city = c.city "如上,如果有这样的where ,就 将这个where 之后的内容 前后加上括号和自己写的一段内容,即效果如下
... where ( ( a.area = b.area or a.area= c.area ) and a.city = c.city ) and 1=2
然后返回这个被变动过的sql如果找不到这样的where 就返回"".
很实用的,在线欢迎拍砖
符合要求的where后的内容全都放在()内?这样的where能保证最多只有一个吗?
如果找不到这样的where 就返回""又是什么意思?String sql = @" select a.*,b.* ,c.* , a.zl || a.hm as zlhm,
(select top 1 kindname from codetable1 where t1.xh= a.xh and t1.xh like '10%') as kname
from table1 a, table2 b , table3 c where ( a.area = b.area or a.area= c.area ) and a.city = c.city ";
string customContent = "and 1=2";
Regex reg = new Regex(@"(?is)(?<!\([^()]*)where(?![^()]*\))(.+)");
string result = reg.Replace(sql, " where ( $1 ) " + customContent);
richTextBox2.Text = result;