我想要的是:
1、判断
2、求和
例如:
判断:表中的A、B、C三个字段中的值是否为空,为空则输入“0”;不为空则为:1
求和:通过判断再累计这三个字段的值例:1+0+1=2
set conn=server.create("adodb.connection")
conn.open "你的驱动字符串"
set rs=conn.execute("select a,b,c from yourtable")
if rs.eof or rs.bof then
response.write "无记录"
else
a=rs("a")&"":b=rs("b")&"":c=rs("c")&""
if a="" then
a=0
else
a=1
end if
if b="" then
b=0
else
b=1
end if
if c="" then
c=0
else
c=1
end if
resposne.write a+b+c
end if
rs.close:set rs=nothing
conn.close:set conn=nothing
取值在哪取 还要连接数据库么 具体的可加我QQ 详细说说1395064310
可以在数据库的sql写好就可以了case when
从数据库取啊;希望能贴出完整代码.谢谢,感激不尽.
问题在哪里?
int Val= String2Int(A) + String2Int(B) + String2Int(C);
int String2Int(string Val)
{
if(string.IsNullOrEmpyt(Val))
{
return 0;
}
else
{
return 1;
}
}
您可以通过 SQL 语句实现您所需的判断和求和功能。以下为示例 SQL 语句:
SELECT SUM(CASE
WHEN A IS NULL OR A = '' THEN 0
ELSE 1
END
+ CASE
WHEN B IS NULL OR B = '' THEN 0
ELSE 1
END
+ CASE
WHEN C IS NULL OR C = '' THEN 0
ELSE 1
END
) AS total
FROM your_table;
解释如下: