【发布时间】:2017-09-16 16:51:38
【问题描述】:
我有一个要求,我想删除 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# 中执行此操作的最佳方法是什么?我可以使用正则表达式还是有更好的方法?
【问题讨论】:
-
反其道而行之;
where (column1 = @c1 or @c1 is null) and (column2 = 10). -
所以每次要删除
where column1 = @c1? -
如果“是”是@WhatsThePoint 问题的答案:当有多个语句时,它总是第一个 where 语句吗?
-
在我看来就像XY problem。如果您描述最初的问题,也许会更有效。
-
是的@WhatsThePoint