-
Notifications
You must be signed in to change notification settings - Fork 1
/
PROCEDURE.sql
131 lines (117 loc) · 2.72 KB
/
PROCEDURE.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
123
124
125
126
127
128
129
130
131
use OrderingSystemDb;
EXECUTE sp_executesql N'
CREATE PROCEDURE [Customer_ReadAll]
AS
BEGIN
SET NOCOUNT ON;
SELECT * FROM Customer
END'
EXECUTE sp_executesql N'
CREATE PROCEDURE Customer_ReadById
@Id int
AS
BEGIN
SET NOCOUNT ON;
SELECT * from Customer
WHERE CustomerId = @Id
END'
EXECUTE sp_executesql N'
CREATE PROCEDURE Customer_Add
@Id int ,
@Email varchar(50),
@CustomerPass varchar(20),
@Name varchar(20),
@SecondName varchar(20),
@Surname varchar(20)
AS
BEGIN
SET NOCOUNT ON;
IF EXISTS (SELECT * FROM dbo.Customer WHERE
CustomerId != @Id)
INSERT INTO dbo.Customer VALUES
(@Id,
@Email,
@CustomerPass,
@Name,
@SecondName,
@Surname)
END'
exec Customer_Add 3,'[email protected]','dsfewfr','Ozge','','Aybars'
EXECUTE sp_executesql N'
CREATE PROCEDURE Customer_Add_Address
@Id int ,
@CustomerId int,
@AddressName varchar(20),
@AddressDescription varchar(50)
AS
BEGIN
SET NOCOUNT ON;
IF EXISTS (SELECT * FROM dbo.CustomerAddress WHERE
AddressId != @Id)
INSERT INTO dbo.CustomerAddress VALUES
(@Id,
@CustomerId,
@AddressName,
@AddressDescription
)
END'
exec Customer_Add_Address 3,3,'Ozge Ev','Yasar Uni Kutuphane 3kat'
EXECUTE sp_executesql N'
CREATE PROCEDURE [Customer_ReadAll_Address]
AS
BEGIN
SET NOCOUNT ON;
SELECT * FROM CustomerAddress
END'
EXECUTE sp_executesql N'
CREATE PROCEDURE Customer_ReadById_Address
@Id int
AS
BEGIN
SET NOCOUNT ON;
SELECT * from CustomerAddress
WHERE CustomerId = @Id
END'
EXECUTE sp_executesql N'
CREATE PROCEDURE Customer_Bill
@Id int
AS
BEGIN
SET NOCOUNT ON;
SELECT
tblOrder.OrderId,
tblOrder.OrderDate ,
Customer.CustomerId,
Customer.Name,
Customer.Surname,
CustomerAddress.AddressDescription,
tblOrder.TotalPrice
FROM tblOrder
INNER JOIN Customer ON tblOrder.CustomerId = Customer.CustomerId
INNER JOIN CustomerAddress ON Customer.CustomerId = CustomerAddress.CustomerId
INNER JOIN CustomerContact ON Customer.CustomerId = CustomerContact.CustomerId
WHERE tblOrder.CustomerId = @Id
END'
EXECUTE sp_executesql N'
CREATE PROCEDURE Product_Add
@ProductId int ,
@CategoryId int,
@ProductName varchar(20),
@ProductDescription varchar(20),
@ProductPrice int,
@ProductCalorie int,
@Stock int
AS
BEGIN
SET NOCOUNT ON;
IF EXISTS (SELECT * FROM dbo.Product WHERE
ProductId != @ProductId)
INSERT INTO dbo.Product VALUES
(@ProductId,
@CategoryId,
@ProductName,
@ProductDescription,
@ProductPrice,
@ProductCalorie,
@Stock)
END'