数据库

本类阅读TOP10

·SQL语句导入导出大全
·SQL Server日期计算
·SQL语句导入导出大全
·SQL to Excel 的应用
·Oracle中password file的作用及说明
·MS SQLServer OLEDB分布式事务无法启动的一般解决方案
·sqlserver2000数据库置疑的解决方法
·一个比较实用的大数据量分页存储过程
·如何在正运行 SQL Server 7.0 的服务器之间传输登录和密码
·SQL中两台服务器间使用连接服务器

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
游标代码举例

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

1.对低于当前平均价格的书,均提价50%

2对于高于或等于当前平均价格的书,均降价25%

代码如下:

declare title_update cursor

     for select title_id,price from titles

     for update

go

局部变量

declare @avg_price money,@title_id tid,@price money

open title_update

begin tran

计算平均书价

select @avg_price=avg(price) from titles holdlock

fetch title_update into @title_id,@price

while @@sqlstatus!=2

begin

if  @@sqlstatus=1

begin

rollback tran

raiserror 21001 "Fetch failed in cursor"

close title_update

deallocate cursor title_update

return

end

if @price<@avg_price

提价50%

update titles set price = price * $1.50

where current of title_update

else

降价25%

update titles set price = price * $.75

where current of title_update

if @@error!=0

begin

rollback tran

raiserror 22001 "Update failed"

close title_update

deallocate cursor title_update

return

end

fetch title_update into @title_id,@price

end

commit

close title_update

deallocate cursor title_update

go

 

 

 

 

 

 




相关文章

相关软件