日期:2014-05-18  浏览次数:20725 次

急啊!各位大侠救命啊!
ALTER PROCEDURE [dbo].[pr_Insert]

AS
BEGIN
 begin transaction
declare @top money
declare @bookId money
declare @id int
declare @i int
save transaction after_insert
set @i=5
set @top=(select top 1 price from ADBook where showdate=(Select CONVERT(varchar(100), GETDATE(), 102)) order by price desc)
set @id=(select top 1 userId from ADBook where showdate=(Select CONVERT(varchar(100), GETDATE(), 102)) order by price desc)
set @bookId=(select top 1 adbookId from ADBook where showdate=(Select CONVERT(varchar(100), GETDATE(), 102)) order by price desc)
update Users set [money]=[money]-@top where userId=@id
while(@i>0)
begin
set @top=(select top 1 price from ADBook
 where adbookId not in (@bookId) and showdate=(Select CONVERT(varchar(100), GETDATE(), 102))
 order by price desc)
set @id=(select top 1 userId from ADBook
 where adbookId not in (@bookId) and showdate=(Select CONVERT(varchar(100), GETDATE(), 102))
 order by price desc)
set @bookId=(select top 1 adbookId from ADBook
 where adbookId not in (@bookId) and showdate=(Select CONVERT(varchar(100), GETDATE(), 102))
 order by price desc)

update Users set [money]=[money]-@top where userId=@id
set @i=@i-1
end

if @@error!=0
begin
rollback transaction after_insert
commit transaction
end
commit transaction

END

下面的是数据库表
create table Users
(
userId int identity(1,1) primary key, --用户ID
userPwd varchar(50) not null, --密码
userName varchar(50) not null, --用户名(店名)
[money] int --金币
)

create table ADBook
(
adbookId int identity(1,1) primary key, --预拍ID
address varchar(50), --前往地址
imagedata image, --图片
imagepath varchar(50), --图片路径
price int, --竞拍价格
status int, --竞拍状态 0,竞拍结束 1,正在竞拍
showdate varchar(50), --展示日期
aucdate smalldatetime, --竞拍日期
ip varchar(50), --用户IP
userId int references Users(userId) not null --用户ID
)

竞拍结束 用户要减去竞拍到的的竞拍价(钱数前6得到) 上面的存储过程出问题了 可能是循环里

------解决方案--------------------
额 什么错误 发来。

------解决方案--------------------
太长了,看得花眼.
------解决方案--------------------
存储过程的调试需要你自己PRINT出来看看。
------解决方案--------------------
楼主别着急, 慢慢看程序.

程序的业务逻辑大伙很难帮你的.