标签:
USE Hotel GO --阶段1:查询入住在指定客房类型的客房的顾客数 IF EXISTS(SELECT * FROM sysobjects WHERE name=‘usp_GetGuestNumByTypeName‘) DROP PROC usp_GetGuestNumByTypeName GO CREATE PROCEDURE usp_GetGuestNumByTypeName @typeName varchar(50), ----客房类型名称 @result int OUTPUT ---返回值,居住在指定客房类型客房的顾客数 AS SELECT @result = count(1) FROM GuestRecord WHERE RoomID IN (SELECT roomID FROM Room WHERE RoomTypeID= (SELECT TypeID FROM RoomType WHERE TypeName = @typeName)) PRINT @result GO --调用存储过程 SET NOCOUNT ON DECLARE @Count int DECLARE @RoomType varchar(20) SET @RoomType = ‘标准间‘ EXEC usp_GetGuestNumByTypeName @RoomType,@Count OUTPUT PRINT ‘入住酒店‘ + @RoomType + ‘的客人总人数是:‘ + CAST(@Count AS varchar(10))
IF EXISTS(SELECT * FROM sysobjects WHERE name=‘usp_GetRoomInfo‘) DROP PROC usp_GetRoomInfo GO CREATE procedure usp_GetRoomInfo @roomID int AS IF @roomID=-1 SELECT a.RoomID, a.BedNum, a.RoomStateID, a.Description, a.GuestNum, a.RoomTypeID, b.TypeName, b.TypePrice, RTRIM(c.RoomStateName) AS RoomStateName FROM [Room] a INNER JOIN [RoomType] b ON a.RoomTypeID = b.TypeID INNER JOIN [RoomState] c ON a.RoomStateID = c.RoomStateID ELSE SELECT a.RoomID, a.BedNum, a.RoomStateID, a.Description, a.GuestNum, a.RoomTypeID, b.TypeName, b.TypePrice, RTRIM(c.RoomStateName) AS RoomStateName FROM Room a INNER JOIN [RoomType] b ON a.RoomTypeID = b.TypeID INNER JOIN [RoomState] c ON a.RoomStateID = c.RoomStateID WHERE roomID = @roomID GO --调用存储过程 /* DECLARE @RoomID int SET @RoomID = 1008 EXEC usp_GetRoomInfo @RoomID */ EXEC usp_GetRoomInfo -1
IF EXISTS(SELECT * FROM sysobjects WHERE name=‘usp_deleteRoomTypeById‘) DROP PROC usp_deleteRoomTypeById GO CREATE PROCEDURE usp_deleteRoomTypeById @typeName varchar(20) ----客房类型 AS DECLARE @typeID int SELECT @typeID=TypeID FROM RoomType WHERE TypeName = @typeName IF NOT EXISTS (SELECT * FROM Room WHERE RoomTypeID = @typeID) --Room表里没有相关信息时才删除 BEGIN DELETE FROM RoomType WHERE TypeID=@typeID return @@ROWCOUNT END ELSE return -1 GO --调用存储过程 DECLARE @RoomTYPE varchar(20) DECLARE @Result int SET @RoomTYPE = ‘三人间‘ EXEC @Result=usp_deleteRoomTypeById @RoomTYPE IF (@Result > 0) PRINT ‘删除酒店客房类型是‘+ @RoomTYPE +‘的记录‘ + CAST(@Result AS varchar(10)) + ‘条‘ ELSE PRINT ‘删除酒店客房类型是‘+ @RoomTYPE +‘的记录,失败‘
标签:
原文地址:http://www.cnblogs.com/wlx520/p/4501957.html