我有以下存储过程进行预约。我没有完成插入值的前端所以我使用sql server菜单中的execute storage过程插入到数据库中但是它给了我{{1消息
subquery returned more than 1 value and 1 row affected
这是选择ALTER PROCEDURE [dbo].[Usp_makereservation]
--roombookingdetails
@refno VARCHAR(50),
@propertyid int,
@roomtype VARCHAR(3),
@groupcode VARCHAR(30),
@companycode VARCHAR(10),
@arrivaldate DATETIME,
@arrivalplan VARCHAR(3),
@departuredate DATETIME,
@departureplan VARCHAR(3),
@createdby INT,
--roombookingguestdetails
@subsrno VARCHAR(50),
@roomno VARCHAR(30),
@guesttitle VARCHAR(30),
@lname VARCHAR(50),
@fname VARCHAR(50),
@mname VARCHAR(50),
@address VARCHAR(100),
@city VARCHAR(30),
@state VARCHAR(30),
@country INT,
@zipcode VARCHAR(50),
@telno VARCHAR(15),
@mobile VARCHAR(15),
@fax VARCHAR(50),
@gueststatus INT,
@designation VARCHAR(50),
@occupation VARCHAR(50),
@arrivalfrom VARCHAR(50),
@departureto VARCHAR(50),
@leader BIT,
@spclinstrctn VARCHAR(1000),
@checkinflg BIT,
--roombookingoccupancy
@singlebooked INT,
@singleprovisional INT,
@singleconfirmed INT,
@singlewaitlisted INT,
@doublebooked INT,
@doubleprovisional INT,
@doubleconfirmed INT,
@doublewaitlisted INT,
@triplebooked INT,
@tripleprovisional INT,
@tripleconfirmed INT,
@triplewaitlisted INT,
@quadbooked INT,
@quadprovisional INT,
@quadconfirmed INT,
@quadwaitlisted INT,
@marketsegID INT,
@businesssrcID INT,
@guestcategoryID INT,
@gueststatusID INT,
@totalpax INT,
@adultpax INT,
@childpax INT,
@infantpax INT,
@extraadultpax INT,
@extrachildpax INT,
@complementarypax INT,
@noshow INT,
@checkinrooms INT,
@checkinpax INT
AS
BEGIN
BEGIN try
BEGIN TRAN
INSERT INTO roombookingdetails
(reservationno,
srno,
refno,
propertyid,
roomtype,
groupcode,
companycode,
arrivaldate,
arrivalplan,
depaturedate,
depatureplan,
createdon,
createdby)
VALUES ((SELECT Isnull(Max(reservationno) + 1, 1)
FROM roombookingdetails),
(SELECT Isnull(Max(srno) + 1, 1)
FROM roombookingdetails),
@refno,
@propertyid,
@roomtype,
@groupcode,
@companycode,
@arrivaldate,
@arrivalplan,
@departuredate,
@departureplan,
Getdate(),
@createdby)
INSERT INTO roombookingguestdetails
(reservationno,
srno,
subsrno,
roomno,
guesttitle,
lastname,
firstname,
midname,
[address],
city,
[state],
country,
zipcode,
telno,
mobile,
fax,
gueststatus,
designation,
occupation,
arrivalfrom,
depatureto,
leader,
specialinstruction,
checkinflag,
createdon,
createdby)
VALUES ((SELECT [reservationno]
FROM roombookingdetails),
(SELECT Isnull(Max(srno) + 1, 1)
FROM roombookingguestdetails),
@subsrno,
@roomno,
@guesttitle,
@lname,
@fname,
@mname,
@address,
@city,
@state,
@country,
@zipcode,
@telno,
@mobile,
@fax,
@gueststatus,
@designation,
@occupation,
@arrivalfrom,
@departureto,
@leader,
@spclinstrctn,
@checkinflg,
Getdate(),
@createdby)
INSERT INTO roombookingoccupancy
(reservationno,
srno,
singlebooked,
singleprovisional,
singleconfirmed,
singlewaitlisted,
doublebooked,
doubleprovisional,
doubleconfirmed,
doublewaitlisted,
tripplebooked,
trippleprovisional,
trippleconfirmed,
tripplewaitlisted,
quadbooked,
quadprovisional,
quadconfirmed,
quadwaitlisted,
marketsegmentid,
businesssourceid,
guestcategoryid,
gueststatusid,
totalpax,
adultpax,
childpax,
infantpax,
extraadultpax,
extrachildpax,
complementrypax,
noshow,
checkinrooms,
checkinpax,
createdon,
createdby)
VALUES ((SELECT [reservationno]
FROM roombookingdetails),
(SELECT Isnull(Max(srno) + 1, 1)
FROM roombookingoccupancy),
@singlebooked,
@singleprovisional,
@singleconfirmed,
@singlewaitlisted,
@doublebooked,
@doubleprovisional,
@doubleconfirmed,
@doublewaitlisted,
@triplebooked,
@tripleprovisional,
@tripleconfirmed,
@triplewaitlisted,
@quadbooked,
@quadprovisional,
@quadconfirmed,
@quadwaitlisted,
@marketsegID,
@businesssrcID,
@guestcategoryID,
@gueststatusID,
@totalpax,
@adultpax,
@childpax,
@infantpax,
@extraadultpax,
@extrachildpax,
@complementarypax,
@noshow,
@checkinrooms,
@checkinpax,
Getdate(),
@createdby)
COMMIT TRAN
END try
BEGIN catch
PRINT 'Rollback'
SELECT ERROR_NUMBER() AS ErrorNumber, ERROR_SEVERITY() AS ErrorSeverity, ERROR_STATE() AS ErrorState, ERROR_PROCEDURE() AS ErrorProcedure, ERROR_LINE() AS ErrorLine, ERROR_MESSAGE() AS ErrorMessage;
ROLLBACK
END catch
END
命令
execute stored procedure
答案 0 :(得分:1)
您的下列声明可能会返回超过单个值的错误。 请检查一下。
> SELECT [reservationno] FROM roombookingdetails
您已在插入声明中使用过它。
答案 1 :(得分:0)
当存在此类问题或存在超过1条记录时,您必须在子查询中使用where clause
,Top operator
,Min,Max,Avg
。
答案 2 :(得分:-1)
从第一次插入
替换此(SELECT [reservationno] FROM roombookingdetails)
有了这个
(SELECT Isnull(Max(reservationno) + 1, 1) FROM roombookingguestdetails)
和第二次插入的(SELECT [reservationno] FROM roombookingdetails)
使用此(SELECT Isnull(Max(reservationno) + 1, 1) FROM (RoomBookingOccupancy)
解决了我的问题