如何在storedporcedure中使用count [英] how to use count in a storedporcedure
问题描述
嗨朋友们,
以下是我的customerdetails表值
Hi friends,
The following is my table value for customerdetails
CustId CustName BookingDate Noofseats RowName
111 Rajkumar 2013-05-08 00:00:00.000 5 A
112 palani 2013-05-08 00:00:00.000 8 A
我的查询是
and my query is
alter procedure sp_insertticketsforcustomer(@custid int,@custname varchar(50),@date datetime,@noofseats int,@rowname char(10))
as
begin
declare @noofcounts int
select @noofcounts= COUNT(Noofseats) from CustomerDetails where RowName=@rowname
select @noofcounts
end
这里我只想选择已经分配给特定rowname的座位数量,当我给座位超过可用性时,它会返回行中有多少座位。我只选择如何为特定行分配席位。
here i just want to select how many seats already allocated for a particular rowname and when i given seats more than availablity it shoud return how many seats available in the row.here i just select how seats allocated for particular row.
exec sp_insertticketsforcustomer 113,''palani'',''2013-05-08 00:00:000'',30,''A''
这是我的下一个输入,所以当执行它时返回可用的座位,不足以进行注册。当我执行时这个查询它返回2为noofseats而不是13.how我可以改变这个。可用座位是40,设置在另一个表中。
谢谢
this is my next input so when this execute it return available seats no not enough for registration.when i execute this query it return 2 for noofseats rather than 13.how can i change this one. available seats is 40 that is set in another table.
Thank you
推荐答案
使用 SUM 不计数
Use SUM Not Count
alter procedure sp_insertticketsforcustomer(@custid int,@custname varchar(50),@date datetime,@noofseats int,@rowname char(10))
as
begin
declare @noofcounts int
select @noofcounts= SUM(Noofseats) from CustomerDetails where RowName=@rowname
select @noofcounts
end
< br $>
快乐编码!
:)
Happy Coding!
:)
这篇关于如何在storedporcedure中使用count的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!