读书人

急各位大侠

发布时间: 2012-03-09 16:54:56 作者: rapoo

急啊!各位大侠救命啊!
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
(
userIdint identity(1,1)primary key,--用户ID
userPwdvarchar(50)not null,--密码
userNamevarchar(50)not null,--用户名(店名)
[money]int--金币
)

create table ADBook
(
adbookIdint identity(1,1)primary key,--预拍ID
addressvarchar(50),--前往地址
imagedataimage,--图片
imagepathvarchar(50),--图片路径
priceint,--竞拍价格
statusint,--竞拍状态 0,竞拍结束 1,正在竞拍
showdatevarchar(50),--展示日期
aucdatesmalldatetime,--竞拍日期
ipvarchar(50),--用户IP
userIdintreferences Users(userId) not null --用户ID
)

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

[解决办法]
额 什么错误 发来。

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

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


读书人网 >SQL Server

热点推荐