CREATE PROCEDURE dbo.IssueBook
(
@bookid nvarchar(50),
@ano nvarchar(50),
@mid int,
@librarian varchar(10),
@quantity int
)
AS
declare @cnt int
declare @msg varchar(100)
if not exists(select * from books where bookid = @bookid and quantity = @quantity)
begin
raiserror('Book is not available',16,1);
return;
end;
select @cnt = count(bookid) from issues where mid = @mid;
if (@cnt >= 2)
begin
raiserror('Maximum Limit Has Been Reached For Member!',16,1);
return;
end;
begin tran
begin try
update books set quantity [email protected] where bookid= @bookid;
insert into issues values (@bookid, @mid, getdate(), @librarian, @ano);
commit tran
end try
begin catch
rollback tran
/* select @msg = error_message() */
raiserror('Unknown Error', 16,1);
end catch
我想改變quantity
場的值在SQL表我怎麼能做到這一點,請幫助我,我嘗試過很多事情,但他們沒有工作,我將非常感激給你...我要減少數量字段和減少其數量
它看起來像@Quantity不應該是一個參數,在所有的,你可以只從表中獲取它在剛開始的時候你正在檢查可用性 - 你應該只是更新...數量=數量-1沒有變量。 –