[英]Remove conditions in Where clause in a SQL query
我有一个要删除SQL查询字符串中“ where”子句中条件的要求。
如果我的查询是
Select *
from table1
where column1 = @c1 and column2 = 10
那么删除后应该是
Select *
from table1
where column2 = 10
如果我的SQL查询是
Select *
from table1
where column1 = @c1
那么删除后应该是
Select *
from table1
用C#做到这一点的最佳方法是什么? 我可以使用Regex还是有更好的方法?
这不是最漂亮的方法,但是可以解决您的问题。
return query.Replace((query.IndexOf(" and ") != -1 ? "column1 = @c1 and " : " where column1 = @c1"), string.Empty);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.