如何在不同条件下拆分查询,并检查哪种条件在C#中的查询失败



我正在编写一个代码,如果我们放置查询,它将显示查询的 where 子句在C#中没有获取任何数据。

查询结构类似于

select * from ABD where a=0 and b= 42 and c=(Select c from azs) or f=89 or x=10

如果您正在使用已知查询,则可以编写查询以指示每个行的哪个条件将返回到每行的true或false,如下所示:

select
  case when a=0 then 1 else 0 end as 'term1',
  case when b=42 then 1 else 0 end as 'term2',
  case when c=(select c from azs) then 1 else 0 end as 'term3',
  case when f=89 then 1 else 0 end as 'term4',
  case when x=10 then 1 else 0 end as 'term5'
from ABD

如果您的问题更为笼统,因为您不知道实际查询,那么您将需要编写一个可以将输入查询解析为单个条款的程序。可以通过使用字符串索引和拆分(类似(来定位单个术语来实现简单方案。也可以通过实现简单的SQL解析器来完成。我建议具有讽刺意味的是C#中的解析器的绝佳框架,甚至包括SQL样品语法。

最新更新