Im doing a reservation application and was wondering how would i handle the following scenario; if a booking has 2 or more “extra” items on it how do i create a SP or a trigger even to handle this? the SP i have now works fine for a booking with a single extra item on it. Im i making any sense?
ALTER PROCEDURE [dbo].[CreateBooking]
@DateFrom datetime,
@DateTo datetime,
@RoomID int,
@PersonID int,
@ProductID int,
@OrderAmount int
AS
BEGIN TRANSACTION
SET NOCOUNT ON;
INSERT INTO booking(created_on, startdate, enddate, room_id, person_id)
VALUES (getdate(), @DateFrom, @DateTo, @RoomID, @PersonID)
IF @@error <> 0
ROLLBACK TRANSACTION
ELSE
INSERT INTO booking_details (booking_id,prod_id,order_amount)
VALUES (SCOPE_IDENTITY(), @ProductID, @OrderAmount)
COMMIT TRANSACTION
You can pass an xml parameter then loop through it and write them.