-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions
73 lines (44 loc) · 2.25 KB
/
functions
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
CREATE FUNCTION fourthgeneration_db:PERCENT_ONTIME_CUSTOMERSHIPMENTS (year INT, month INT, warehouse CHAR(500) )
RETURNING decimal;
DEFINE v_total_monthly_orders INT;
DEFINE v_shipped_on_time INT;
DEFINE v_percentage decimal;
--insert function body here
SELECT count(*) AS totalmonthlyorders, shipped_on_time, ((shipped_on_time * 100) / count(*))
INTO v_total_monthly_orders, v_shipped_on_time, v_percentage
FROM stoordre,
(SELECT count(dayslate) AS shipped_on_time FROM
(SELECT (ship_date - to_ship_date) AS dayslate FROM stoordre WHERE like_type = 'REG' AND warehouse_code = warehouse AND TO_CHAR(order_date, '%Y') = year AND ship_date IS NOT NULL AND MONTH(order_date) = month)
WHERE dayslate <= 0)
WHERE like_type = 'REG' AND warehouse_code = warehouse AND TO_CHAR(order_date, '%Y') = year AND ship_date IS NOT NULL AND MONTH(order_date) = month GROUP BY shipped_on_time;
RETURN v_percentage;
END FUNCTION;
CREATE FUNCTION two_returns (stockno INT) RETURNING CHAR (15);
DEFINE des CHAR(15);
END FUNCTION;
DROP FUNCTION fourthgeneration_db:CUSTOMER_NAME;
CREATE FUNCTION fourthgeneration_db:PERCENT_ONTIME_VENDORDELIVERIES (year INT, month INT, warehouse CHAR(500) )
RETURNING decimal;
DEFINE v_total_monthly_orders INT;
DEFINE v_shipped_on_time INT;
DEFINE v_percentage decimal;
--insert function body here
SELECT count(*) AS totalmonthlyorders, shipped_on_time, ((shipped_on_time * 100) / count(*))
INTO v_total_monthly_orders, v_shipped_on_time, v_percentage
FROM stuordre,
(SELECT count(dayslate) AS shipped_on_time FROM
(SELECT (ship_date - required_date) AS dayslate FROM stuordre WHERE po_type = 'REG' AND whse_shipto = warehouse AND TO_CHAR(po_date, '%Y') = year AND ship_date IS NOT NULL AND MONTH(po_date) = month)
WHERE dayslate <= 0 )
WHERE po_type = 'REG' AND whse_shipto = warehouse AND TO_CHAR(po_date, '%Y') = year AND ship_date IS NOT NULL AND MONTH(po_date) = month GROUP BY shipped_on_time;
RETURN v_percentage;
END FUNCTION;
CREATE FUNCTION fourthgeneration_db:CUSTOMER_NAME (billCode CHAR (50))
RETURNING CHAR (500);
DEFINE v_customerName CHAR (500);
--insert function body here
SELECT DISTINCT bus_name
INTO v_customerName
FROM stoordre
WHERE bill_to_code = ();
RETURN v_customerName;
END FUNCTION;