-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHDdecisions_DB.sql
187 lines (151 loc) · 4.55 KB
/
HDdecisions_DB.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
CREATE DATABASE HDdecisions_DB;
USE [HDdecisions_DB]
GO
/****** Object: Table [dbo].[AuditReportDetails] Script Date: 17-07-2020 17:44:20 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[AuditReportDetails] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[PersonalInfoId] INT NOT NULL,
[BankDetails] INT NOT NULL,
[CaptureDate] DATETIME NOT NULL
);
/****** Object: Table [dbo].[BankDetails] Script Date: 17-07-2020 17:44:45 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[BankDetails] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[BankName] NCHAR (50) NULL,
[CreditcardType] NCHAR (50) NULL,
[AnnualPercentageRate] FLOAT (53) NULL
);
/****** Object: Table [dbo].[PersonalInfo] Script Date: 17-07-2020 17:45:13 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PersonalInfo] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[FirstName] NCHAR (50) NULL,
[LastName] NCHAR (50) NULL,
[DOB] DATE NULL,
[AnnualIncome] FLOAT (53) NULL,
[BankId] INT NULL,
[Age] INT NULL,
[Lastupdated] DATETIME NOT NULL
);
/****** Object: SqlProcedure [dbo].[GetAllApplicantInformation] Script Date: 17-07-2020 17:46:01 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
DROP PROCEDURE [dbo].[GetAllApplicantInformation];
GO
-- =============================================
-- Author: Sudhan Radhakrishnan
-- Create date: 18-July-2021
-- Description: Get All Applicant Information
-- =============================================
CREATE PROCEDURE GetAllApplicantInformation
AS
BEGIN
SELECT
P.FirstName + ' ' + P.LastName AS FullName,
P.[AnnualIncome] as AnnualIncome,
CASE WHEN B.[BankName] = 'NoBank'
THEN 'Age is under 18'
ELSE B.[BankName]
END AS BankDetails,
CASE WHEN P.[Age] IS NULL
THEN '100'
ELSE P.[Age]
END AS Age,
P.[Lastupdated] as AttemptDate
FROM [dbo].[PersonalInfo] P
INNER JOIN [dbo].[AuditReportDetails] A ON A.[PersonalInfoId] = P.[Id]
INNER JOIN [dbo].[BankDetails] B ON B.[Id] = A.[BankDetails]
WHERE P.BankId IS NOT NULL;
END
/****** Object: SqlProcedure [dbo].[InsertAuditReportDetails] ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
DROP PROCEDURE [dbo].[InsertAuditReportDetails];
GO
-- =============================================
-- Author: Sudhan Radhakrishnan
-- Create date: 18-July-2021
-- Description: Insert Audit Report Details
-- =============================================
Create PROCEDURE InsertAuditReportDetails
@PersonalInfoId int,
@BankDetails int,
@Identity int OUT
As
BEGIN
--This means the record isn't in AuditReportDetails table already, let's go ahead and add it
Insert into AuditReportDetails (PersonalInfoId,BankDetails,CaptureDate)
Values (@PersonalInfoId,@BankDetails,GETDATE())
SET @Identity = SCOPE_IDENTITY()
END
/****** Object: SqlProcedure [dbo].[InsertPersonalInfo] Script Date: 17-07-2020 17:47:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
DROP PROCEDURE [dbo].[InsertPersonalInfo];
GO
-- =============================================
-- Author: Sudhan Radhakrishnan
-- Create date: 18-July-2021
-- Description: To add a new member in PersonalInfo table
-- =============================================
CREATE PROCEDURE InsertPersonalInfo
@FirstName varchar(max),
@LastName varchar(max),
@DOB DATE,
@Age int,
@AnnualIncome Float,
@BankId int,
@Identity int OUT
AS
IF EXISTS (SELECT * FROM PersonalInfo WHERE FirstName = @FirstName and LastName = @LastName and DOB = @DOB and AnnualIncome = @AnnualIncome)
BEGIN
--This means record exists duplicate
SET @Identity = -1
END
ELSE
BEGIN
--This means the record isn't in Table already, let's go ahead and add it
Insert into PersonalInfo (FirstName,LastName,DOB,AnnualIncome,BankId,Lastupdated,Age)
Values (@FirstName,@LastName,@DOB,@AnnualIncome,@BankId,GETDATE(),@Age)
SET @Identity = SCOPE_IDENTITY()
END
--**************************************** INSERT value into BankDetails**************************************
GO
INSERT INTO [dbo].[BankDetails] (
[BankName],
[CreditcardType],
[AnnualPercentageRate]
)
VALUES
(
'NoBank',
'Under18',
0
),
(
'Barclay',
'BarclayCard',
10
),
(
'Vanquis',
'VanquisVisa',
20
);