create table 表(a int,no1 varchar(10),no2 varchar(10),no3 varchar(10),no4 varchar(10)
,total as case no1 when 1 then 1 else 0 end
+case no2 when 1 then 1 else 0 end
+case no3 when 1 then 1 else 0 end
+case no4 when 1 then 1 else 0 end
)
,total as case no1 when 1 then 1 else 0 end
+case no2 when 1 then 1 else 0 end
+case no3 when 1 then 1 else 0 end
+case no4 when 1 then 1 else 0 end
)
解决方案 »
- 求一个关于合同时间的SQL
- 求一简单的触发器,如何写?
- 如果进行跨服务器连接,但所要连接的服务器SA设了密码如何解决
- 绝对经典的问题!在线等!
- 请问数据量大的情况下select是不是不应该用newID啦,它到底是什么原理
- 急求数据库定期备份单个表的方法
- SQL 2005 还原时出现的怪异问题`
- 紧急!如何用SQL2000的BCP工具倒入由SQL6.5BCP工具倒出的数据(倒出倒入时,没有使用format file)在线等。
- sql高手看过来:关于sql的问题!
- 开发基于远程应用的进销存管理软件使用什么开发工具好?
- 为什么连接不成功 需要改数据库那个地方????
- 关于库表字段属性的扩展——————小弟谢谢了!急!
case no1 when 1 then 1 else 0 end
+case no2 when 1 then 1 else 0 end
+case no3 when 1 then 1 else 0 end
+case no4 when 1 then 1 else 0 end
--如果是在企业管理器中设计表,则直接在total字段的公式中输入:
case no1 when 1 then 1 else 0 end
+case no2 when 1 then 1 else 0 end
+case no3 when 1 then 1 else 0 end
+case no4 when 1 then 1 else 0 end
create table 表(a int,no1 varchar(10),no2 varchar(10),no3 varchar(10),no4 varchar(10)
,total as case no1 when 'X' then 1 else 0 end
+case no2 when 'X' then 1 else 0 end
+case no3 when 'X' then 1 else 0 end
+case no4 when 'X' then 1 else 0 end--2.在现有表上添加字段
alter table 表 add total as
case no1 when 'x' then 1 else 0 end
+case no2 when 'x' then 1 else 0 end
+case no3 when 'x' then 1 else 0 end
+case no4 when 'x' then 1 else 0 end
--如果是在企业管理器中设计表,则直接在total字段的公式中输入:
case no1 when 'x' then 1 else 0 end
+case no2 when 'x' then 1 else 0 end
+case no3 when 'x' then 1 else 0 end
+case no4 when 'x' then 1 else 0 end
create table 表(a int,no1 varchar(10),no2 varchar(10),no3 varchar(10),no4 varchar(10)
,total as case no1 when 'X' then 1 else 0 end
+case no2 when 'X' then 1 else 0 end
+case no3 when 'X' then 1 else 0 end
+case no4 when 'X' then 1 else 0 end
)--插入数据
insert 表(a,no1,no2,no3,no4)
select 1,'X','X','X','X'
union all select 2,'','X','X',''
go--显示结果
select * from 表--删除测试
drop table 表/*--测试结果
a no1 no2 no3 no4 total
----------- ---------- ---------- ---------- ---------- -----------
1 X X X X 4
2 X X 2(所影响的行数为 2 行)--*/