22,209
社区成员
发帖
与我相关
我的任务
分享
SELECT *, SIGN(a1)+SIGN(a2)+SIGN(a3)+SIGN(a4)+SIGN(a5)+SIGN(a6) AS [>0]
FROM tableName
create table test(a1 int,a2 int,a3 int,a4 int,a5 int,a6 int)
go
insert into test values(1,0,0,5,0,0)
go
select case when a1 !=0 then 1 else 0 end +
case when a2 !=0 then 1 else 0 end +
case when a3 !=0 then 1 else 0 end +
case when a4 !=0 then 1 else 0 end +
case when a5 !=0 then 1 else 0 end +
case when a6 !=0 then 1 else 0 end
from test
go
drop table test
go
(1 行受影响)
-----------
2
(1 行受影响)