SQL用什么方法统计出一行数据里边有几个空值比较好?
------解决方案--------------------
- SQL code
create table tb (col1 varchar(10),col2 varchar(10),col3 varchar(10),col4 varchar(10),col5 varchar(10))insert into tbselect 'col',null,null,'col4','col5'GOdeclare @String varchar(max)SELECT @String=CONVERT(varchar(20),isnull(col1,'@'))+CONVERT(varchar(20),isnull(col2,'@'))+CONVERT(varchar(20),isnull(col3,'@')) +CONVERT(varchar(20),isnull(col4,'@'))+CONVERT(varchar(20),isnull(col5,'@'))from tbselect datalength(@String)-datalength(REPLACE(@String,'@','')) as 'NULL值个数'GODROP TABLE TB