Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 有没有更好的方法来查找所有列都有值的行?_C#_Vb.net_Sql Server 2005_.net 3.5 - Fatal编程技术网

C# 有没有更好的方法来查找所有列都有值的行?

C# 有没有更好的方法来查找所有列都有值的行?,c#,vb.net,sql-server-2005,.net-3.5,C#,Vb.net,Sql Server 2005,.net 3.5,我需要在结果集中找到每列都不带null的行 这些结果集的列数可变 目前,我能想到的唯一方法是在每个结果集上创建一个视图,并以这种方式进行过滤: select field1, field2, field3, field4, ... from "huge query" where field1 is not null and field2 is not null and field3 is not null and field4 is no

我需要在结果集中找到每列都不带null的行

这些结果集的列数可变

目前,我能想到的唯一方法是在每个结果集上创建一个视图,并以这种方式进行过滤:

 select field1, field2, field3, field4, ...
 from "huge query"
 where field1 is not null and  
       field2 is not null and  
       field3 is not null and  
       field4 is not null and
       ...  is not null
在SQL Server或.net代码(c#或vb.net)中的存储过程/函数中,有没有更好的方法来实现这一点

那么做类似的事情怎么样

 select field1, field2, field3, field4, ...
 from "huge query"
 (return to .net apps or insert into #temptable)
然后在存储过程/函数或.net代码(c#/vb.net)中,循环遍历所有行/列,并标记或删除所有得到空值的行


我说的是超过50种不同类型的结果集,它可能会随着时间的推移而增长,因此我正在寻找一种通用的/易于维护的方法

您的方法并不漂亮,但实际上我认为它会表现得最好。另一种方法是

WHERE (field1 + field2 + field3 + field4) IS NOT NULL

由于空值会传播,如果它们都是相同的数据类型,请重试

where colA + ColB + ColC, etc Is Not Null
如果它们不是,那么首先将它们(那些还不是字符串的)转换为char,然后将它们连接起来

where Str(ColA) + Str(ColB) + Str(ColC), etc Is Not Null

如果字段1、字段2、字段2。。。fieldX是字符串,您可能需要尝试:

select field1, field2, field3, field4, ...
from "huge query"
where field1 + field2 + field3 + ... + fieldX is not null

+我也不知道“+”可以与stringI以外的其他类型一起工作我更新了我的问题,我可能最终使用你的解决方案,如果没有更好的方法检查这个问题,但我仍然会使用我的解决方案“field is not null and…”,因为找到每个字段的数据类型以确保它们不是varchar/char将非常长,不管数据类型是什么,至少每个字段上的“不为空”都会起作用。如果您有许多字段,但它们的类型并不完全相同,那么您的解决方案可能是最好的。。。