更新数据表的操作,用存储过程或者函数完成.100分 update aset Percent=rtrim(isnull(Value,0)*100/(select Value from #T where key=a.key and Order=1))+'%'from #T a 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 --生成测试数据create table #T([Order] int,[Value] int,[Percent] varchar(10),[key] int)insert into #T select 1,100 ,null,1insert into #T select 2,50 ,null,1insert into #T select 3,30 ,null,1insert into #T select 1,170 ,null,3insert into #T select 2,170 ,null,3insert into #T select 3,85 ,null,3insert into #T select 4,50 ,null,3insert into #T select 5,null,null,4--执行更新操作update aset [Percent]=rtrim(isnull(Value,0)*100/isnull((select Value from #T where [key]=a.[key] and [Order]=1),1))+'%'from #T a--输出执行结果select * from #T/*1 100 100% 12 50 50% 13 30 30% 11 170 100% 32 170 100% 33 85 50% 34 50 29% 35 NULL 0% 4*/--删除测试数据drop table #T 求写一函数 安装SQL server 2005时弹出错误窗口 错误:-2146233087 help!误使用delete命令删除了一些数据,还有没有办法修复 查询的结果是null,如何把它在sqlserver里直接变成0,因为我还要拿它做计算 存储嵌套 事务嵌套 的问题 SQL老问题?? SQL字符串小问题 一个存储过程求算法! access导为sql后sql 语句出错-- recordset 相关问题 SQL SERVER 2000的数据是否可以导入 SQL SERVER 7。0,过程中需要注意什么? 求一case语句 关于数据库恢复,急急急
create table #T([Order] int,[Value] int,[Percent] varchar(10),[key] int)
insert into #T select 1,100 ,null,1
insert into #T select 2,50 ,null,1
insert into #T select 3,30 ,null,1
insert into #T select 1,170 ,null,3
insert into #T select 2,170 ,null,3
insert into #T select 3,85 ,null,3
insert into #T select 4,50 ,null,3
insert into #T select 5,null,null,4--执行更新操作
update a
set
[Percent]=rtrim(isnull(Value,0)*100/isnull((select Value from #T where [key]=a.[key] and [Order]=1),1))+'%'
from #T a--输出执行结果
select * from #T
/*
1 100 100% 1
2 50 50% 1
3 30 30% 1
1 170 100% 3
2 170 100% 3
3 85 50% 3
4 50 29% 3
5 NULL 0% 4
*/--删除测试数据
drop table #T