-
Notifications
You must be signed in to change notification settings - Fork 0
/
INSERT1000promotionCodes.sql
69 lines (56 loc) · 2.61 KB
/
INSERT1000promotionCodes.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
USE [system_sprzedazy_biletow_lotniczych]
GO
/****** Object: StoredProcedure [dbo].[INSERT1000promotionCodes] Script Date: 02/02/2021 16:56:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[INSERT1000promotionCodes]
AS
DECLARE @id_promotion INT
SET @id_promotion = 3
DECLARE @number INT
SET @number = 5
DECLARE @rand_num INT
IF EXISTS (SELECT Table_Promotions.id_promotion FROM Table_Promotions WHERE id_promotion = @id_promotion)
BEGIN
PRINT 'Dodaje 1000 kuponów dla promocji nr'
PRINT @id_promotion
WHILE @number <= 1000
BEGIN
SET @rand_num = FLOOR(RAND()*(9999-1000+1)+1000)
PRINT @rand_num
INSERT INTO Table_Promotion_Codes
(
id_promotion,
promotion_code
)
VALUES
(
@id_promotion,
@rand_num
)
SET @number = @number + 1
END
END
ELSE
BEGIN
INSERT INTO Table_Promotions (promotion_name, cut_off) VALUES ('Nowa promocja', 0.0)
SET @id_promotion = (SELECT MAX(Table_Promotions.id_promotion) FROM Table_Promotions)
WHILE @number <= 1000
BEGIN
SET @rand_num = FLOOR(RAND()*(9999-1000+1)+1000)
PRINT @rand_num
INSERT INTO Table_Promotion_Codes
(
id_promotion,
promotion_code
)
VALUES
(
@id_promotion,
@rand_num
)
SET @number = @number + 1
END
END