Skip to content

Commit cca88b5

Browse files
author
Darling Data
committed
Automation: Format and Build SQL File
1 parent b72dd2f commit cca88b5

File tree

14 files changed

+38610
-25116
lines changed

14 files changed

+38610
-25116
lines changed
Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
SET ANSI_NULLS ON;
2-
SET ANSI_PADDING ON;
3-
SET ANSI_WARNINGS ON;
4-
SET ARITHABORT ON;
5-
SET CONCAT_NULL_YIELDS_NULL ON;
6-
SET QUOTED_IDENTIFIER ON;
7-
SET NUMERIC_ROUNDABORT OFF;
8-
SET IMPLICIT_TRANSACTIONS OFF;
9-
SET STATISTICS TIME, IO OFF;
10-
GO
11-
12-
CREATE OR ALTER FUNCTION
13-
dbo.EffectiveAnnualInterestRate_Inline
14-
(
15-
@Rate float,
16-
@Periods integer
17-
)
18-
RETURNS TABLE
19-
AS
20-
RETURN
21-
/*
22-
For support, head over to GitHub:
23-
https://code.erikdarling.com
24-
*/
25-
SELECT
26-
Rate =
27-
CONVERT
28-
(
29-
float,
30-
CASE
31-
WHEN (@Rate < 1)
32-
OR (@Periods < 1)
33-
THEN 0
34-
ELSE POWER(1 + @Rate / @Periods, @Periods) - 1
35-
END
36-
);
37-
GO
1+
SET ANSI_NULLS ON;
2+
SET ANSI_PADDING ON;
3+
SET ANSI_WARNINGS ON;
4+
SET ARITHABORT ON;
5+
SET CONCAT_NULL_YIELDS_NULL ON;
6+
SET QUOTED_IDENTIFIER ON;
7+
SET NUMERIC_ROUNDABORT OFF;
8+
SET IMPLICIT_TRANSACTIONS OFF;
9+
SET STATISTICS TIME, IO OFF;
10+
GO
11+
12+
CREATE OR ALTER FUNCTION
13+
dbo.EffectiveAnnualInterestRate_Inline
14+
(
15+
@Rate float,
16+
@Periods integer
17+
)
18+
RETURNS TABLE
19+
AS
20+
RETURN
21+
/*
22+
For support, head over to GitHub:
23+
https://code.erikdarling.com
24+
*/
25+
SELECT
26+
Rate =
27+
CONVERT
28+
(
29+
float,
30+
CASE
31+
WHEN (@Rate < 1)
32+
OR (@Periods < 1)
33+
THEN 0
34+
ELSE POWER(1 + @Rate / @Periods, @Periods) - 1
35+
END
36+
);
37+
GO
Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,63 @@
1-
SET ANSI_NULLS ON;
2-
SET ANSI_PADDING ON;
3-
SET ANSI_WARNINGS ON;
4-
SET ARITHABORT ON;
5-
SET CONCAT_NULL_YIELDS_NULL ON;
6-
SET QUOTED_IDENTIFIER ON;
7-
SET NUMERIC_ROUNDABORT OFF;
8-
SET IMPLICIT_TRANSACTIONS OFF;
9-
SET STATISTICS TIME, IO OFF;
10-
GO
11-
12-
CREATE OR ALTER FUNCTION
13-
dbo.FutureValue_Inline
14-
(
15-
@Rate float,
16-
@Periods integer,
17-
@Payment float,
18-
@Value float,
19-
@Type integer
20-
)
21-
RETURNS TABLE
22-
AS
23-
RETURN
24-
/*
25-
For support, head over to GitHub:
26-
https://code.erikdarling.com
27-
*/
28-
WITH pre AS
29-
(
30-
SELECT
31-
Type =
32-
ISNULL(@Type, 0),
33-
Value =
34-
ISNULL(@Value, 0),
35-
Term =
36-
POWER(1 + @Rate, @Periods)
37-
38-
),
39-
post AS
40-
(
41-
SELECT
42-
FutureValue =
43-
CASE
44-
WHEN @Rate = 0
45-
THEN (p.Value + @Payment) * @Periods
46-
WHEN (@Rate <> 0
47-
AND p.Type = 0)
48-
THEN p.Value * p.Term + @Payment * (p.Term - 1) / @Rate
49-
WHEN (@Rate <> 0
50-
AND p.Type = 1)
51-
THEN p.Value * p.Term + @Payment * (1 + @Rate) * (p.Term - 1.0) / @Rate
52-
END
53-
FROM pre AS p
54-
)
55-
SELECT
56-
FutureValue =
57-
CONVERT
58-
(
59-
float,
60-
p.FutureValue * -1.
61-
)
62-
FROM post AS p;
63-
GO
1+
SET ANSI_NULLS ON;
2+
SET ANSI_PADDING ON;
3+
SET ANSI_WARNINGS ON;
4+
SET ARITHABORT ON;
5+
SET CONCAT_NULL_YIELDS_NULL ON;
6+
SET QUOTED_IDENTIFIER ON;
7+
SET NUMERIC_ROUNDABORT OFF;
8+
SET IMPLICIT_TRANSACTIONS OFF;
9+
SET STATISTICS TIME, IO OFF;
10+
GO
11+
12+
CREATE OR ALTER FUNCTION
13+
dbo.FutureValue_Inline
14+
(
15+
@Rate float,
16+
@Periods integer,
17+
@Payment float,
18+
@Value float,
19+
@Type integer
20+
)
21+
RETURNS TABLE
22+
AS
23+
RETURN
24+
/*
25+
For support, head over to GitHub:
26+
https://code.erikdarling.com
27+
*/
28+
WITH pre AS
29+
(
30+
SELECT
31+
Type =
32+
ISNULL(@Type, 0),
33+
Value =
34+
ISNULL(@Value, 0),
35+
Term =
36+
POWER(1 + @Rate, @Periods)
37+
38+
),
39+
post AS
40+
(
41+
SELECT
42+
FutureValue =
43+
CASE
44+
WHEN @Rate = 0
45+
THEN (p.Value + @Payment) * @Periods
46+
WHEN (@Rate <> 0
47+
AND p.Type = 0)
48+
THEN p.Value * p.Term + @Payment * (p.Term - 1) / @Rate
49+
WHEN (@Rate <> 0
50+
AND p.Type = 1)
51+
THEN p.Value * p.Term + @Payment * (1 + @Rate) * (p.Term - 1.0) / @Rate
52+
END
53+
FROM pre AS p
54+
)
55+
SELECT
56+
FutureValue =
57+
CONVERT
58+
(
59+
float,
60+
p.FutureValue * -1.
61+
)
62+
FROM post AS p;
63+
GO
Lines changed: 96 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,96 @@
1-
SET ANSI_NULLS ON;
2-
SET ANSI_PADDING ON;
3-
SET ANSI_WARNINGS ON;
4-
SET ARITHABORT ON;
5-
SET CONCAT_NULL_YIELDS_NULL ON;
6-
SET QUOTED_IDENTIFIER ON;
7-
SET NUMERIC_ROUNDABORT OFF;
8-
SET IMPLICIT_TRANSACTIONS OFF;
9-
SET STATISTICS TIME, IO OFF;
10-
GO
11-
12-
CREATE OR ALTER FUNCTION
13-
dbo.InterestPayment_Inline
14-
(
15-
@Rate float,
16-
@Period integer,
17-
@Periods integer,
18-
@Present float,
19-
@Future float,
20-
@Type integer
21-
)
22-
RETURNS TABLE
23-
AS
24-
/*
25-
For support, head over to GitHub:
26-
https://code.erikdarling.com
27-
*/
28-
RETURN
29-
WITH pre AS
30-
(
31-
SELECT
32-
Type =
33-
ISNULL(@Type, 0),
34-
Payment =
35-
(
36-
SELECT
37-
Payment
38-
FROM dbo.Payment_Inline
39-
(
40-
@Rate,
41-
@Periods,
42-
@Present,
43-
@Future,
44-
@Type
45-
)
46-
)
47-
),
48-
post AS
49-
(
50-
SELECT
51-
InterestPayment =
52-
CASE
53-
WHEN (@Period = 1
54-
AND p.Type = 1)
55-
THEN 0
56-
WHEN (@Period = 1
57-
AND p.Type = 0)
58-
THEN (@Present * - 1.)
59-
WHEN (@Period <> 1
60-
AND p.Type = 0)
61-
THEN (
62-
SELECT
63-
FutureValue
64-
FROM dbo.FutureValue_Inline
65-
(
66-
@Rate,
67-
@Period - 1,
68-
p.Payment,
69-
@Present, 0
70-
)
71-
)
72-
WHEN (@Period <> 1
73-
AND p.Type = 1)
74-
THEN (
75-
SELECT
76-
FutureValue - p.Payment
77-
FROM dbo.FutureValue_Inline
78-
(
79-
@Rate,
80-
@Period - 2,
81-
p.Payment,
82-
@Present, 1
83-
)
84-
)
85-
END
86-
FROM pre AS p
87-
)
88-
SELECT
89-
InterestPayment =
90-
CONVERT
91-
(
92-
float,
93-
p.InterestPayment * @Rate
94-
)
95-
FROM post AS p;
96-
GO
1+
SET ANSI_NULLS ON;
2+
SET ANSI_PADDING ON;
3+
SET ANSI_WARNINGS ON;
4+
SET ARITHABORT ON;
5+
SET CONCAT_NULL_YIELDS_NULL ON;
6+
SET QUOTED_IDENTIFIER ON;
7+
SET NUMERIC_ROUNDABORT OFF;
8+
SET IMPLICIT_TRANSACTIONS OFF;
9+
SET STATISTICS TIME, IO OFF;
10+
GO
11+
12+
CREATE OR ALTER FUNCTION
13+
dbo.InterestPayment_Inline
14+
(
15+
@Rate float,
16+
@Period integer,
17+
@Periods integer,
18+
@Present float,
19+
@Future float,
20+
@Type integer
21+
)
22+
RETURNS TABLE
23+
AS
24+
/*
25+
For support, head over to GitHub:
26+
https://code.erikdarling.com
27+
*/
28+
RETURN
29+
WITH pre AS
30+
(
31+
SELECT
32+
Type =
33+
ISNULL(@Type, 0),
34+
Payment =
35+
(
36+
SELECT
37+
Payment
38+
FROM dbo.Payment_Inline
39+
(
40+
@Rate,
41+
@Periods,
42+
@Present,
43+
@Future,
44+
@Type
45+
)
46+
)
47+
),
48+
post AS
49+
(
50+
SELECT
51+
InterestPayment =
52+
CASE
53+
WHEN (@Period = 1
54+
AND p.Type = 1)
55+
THEN 0
56+
WHEN (@Period = 1
57+
AND p.Type = 0)
58+
THEN (@Present * - 1.)
59+
WHEN (@Period <> 1
60+
AND p.Type = 0)
61+
THEN (
62+
SELECT
63+
FutureValue
64+
FROM dbo.FutureValue_Inline
65+
(
66+
@Rate,
67+
@Period - 1,
68+
p.Payment,
69+
@Present, 0
70+
)
71+
)
72+
WHEN (@Period <> 1
73+
AND p.Type = 1)
74+
THEN (
75+
SELECT
76+
FutureValue - p.Payment
77+
FROM dbo.FutureValue_Inline
78+
(
79+
@Rate,
80+
@Period - 2,
81+
p.Payment,
82+
@Present, 1
83+
)
84+
)
85+
END
86+
FROM pre AS p
87+
)
88+
SELECT
89+
InterestPayment =
90+
CONVERT
91+
(
92+
float,
93+
p.InterestPayment * @Rate
94+
)
95+
FROM post AS p;
96+
GO

0 commit comments

Comments
 (0)