I am working on a hotel project and I need to check the availability of rooms. Here the logic is first need to check the room availability if it is not available then I need to check if checkout date entered by the customer is equal to the checkout date of any customer:
ALTER PROCEDURE [dbo].[customerdetails] (@CheckIn DATE, ...)
AS
BEGIN
BEGIN TRY
IF ( (SELECT Available
FROM rooms
WHERE roomtype = @RoomType) > 0 )
BEGIN
INSERT INTO Customerdetail
VALUES (@CheckIn, ...)
END
ELSE IF(SELECT *
FROM Customerdetail
WHERE RoomType = @RoomType
AND CheckOut = @CheckOut)
BEGIN
INSERT INTO Customerdetail
VALUES (@CheckIn, ...)
END
END TRY
BEGIN CATCH
DECLARE @ErrMessage NVARCHAR(max)
SET @ErrMessage=ERROR_MESSAGE()
RAISERROR (@ErrMessage,16,1)
END CATCH
END
But I get an error:
Msg 4145, Level 15, State 1
An expression of non-boolean type specified in a context where a condition is expected, near 'BEGIN'.
IF ((Select COUNT(Available) FROM ROOMS WHERE roomtype=@RoomType) > 0)
– TimEXISTS
could be better. – Martin Smith