-
Notifications
You must be signed in to change notification settings - Fork 2
/
stored_procedures.sql
122 lines (94 loc) · 2.93 KB
/
stored_procedures.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
USE FBS
--procedure 1
Go
CREATE PROCEDURE Flight_Availability
@Departure_Date date,
@Arrival_Date date,
@available char(1) OUTPUT
AS
IF EXISTS(SELECT Flight_ID FROM Flight_Details
WHERE CONVERT(Date,Departure_Date_time) = @Departure_Date
AND CONVERT(Date,Arrival_Date_time) = @Arrival_Date
)
BEGIN
SET @available='Y'
SELECT * FROM Flight_Details
WHERE CONVERT(Date,Departure_Date_time) = @Departure_Date
AND CONVERT(Date,Arrival_Date_time) = @Arrival_Date
END
ELSE
BEGIN
Print 'Flight Detail Doesnt exist'
end
--PROCEDURE 2
Go
CREATE PROCEDURE [dbo].[UpdateFlightDetails]
@flag bit output,-- return 0 for fail,1 for success
@FlightID INT,
@DeptDateTime DATETIME,
@ArivalDateTime DATETIME,
@AirplaneType VARCHAR(100)
AS
BEGIN
Update Flight_Details set Departure_Date_Time = @DeptDateTime,
Arrival_Date_time = @ArivalDateTime,
Airplane_Type = @AirplaneType
Where Flight_ID = @FlightID
set @flag=1;
END
--Procedure 3
Go
CREATE PROCEDURE [dbo].[PassengerCRUD]
@Action VARCHAR(10),
@Passenger_ID int = NULL,
@FName VARCHAR(100) = NULL,
@LName VARCHAR(100) = NULL,
@Email VARCHAR(100) = NULL,
@PNumber BIGINT = NULL,
@Address VARCHAR(100) = NULL,
@city VARCHAR(100) = NULL,
@State VARCHAR(100) = NULL,
@Zipcode VARCHAR(100) = NULL,
@Country VARCHAR(100) = NULL
AS
BEGIN
SET NOCOUNT ON;
--SELECT
IF @Action = 'SELECT'
BEGIN
SELECT Passenger_ID, P_FirstName,P_LastName,P_Email,P_PhoneNumber,P_Address,P_City,
P_State,P_Zipcode,P_Country
FROM Passenger
END
--INSERT
IF @Action = 'INSERT'
BEGIN
INSERT INTO dbo.Passenger([Passenger_ID], [P_FirstName],[P_LastName],[P_Email],[P_PhoneNumber],[P_Address],[P_City],
[P_State],[P_Zipcode],[P_Country] )
VALUES (@Passenger_ID, @FName, @LName, @Email, @PNumber, @Address, @city, @State, @Zipcode, @Country)
END
--UPDATE
IF @Action = 'UPDATE'
BEGIN
UPDATE Passenger
SET Passenger_ID = @Passenger_ID, P_FirstName = @FName, P_LastName = @LName, P_Email= @Email, P_PhoneNumber = @PNumber,
P_Address = @Address, P_City = @city, P_State = @State, P_Zipcode = @Zipcode, P_Country = @Country
WHERE Passenger_ID = @Passenger_ID
END
--DELETE
IF @Action = 'DELETE'
BEGIN
DELETE FROM Passenger
WHERE Passenger_ID = @Passenger_ID
END
END
--Procedure 4
GO
CREATE PROCEDURE UpdatePayment
@paymentID INT,@paid_date date OUTPUT
AS
BEGIN
Update Payment_Status
SET Payment_Status_YN='Y' WHERE Payment_ID=@paymentID
SELECT @paid_date=GETDATE()
END