Professional Documents
Culture Documents
03 Handson Adbase
03 Handson Adbase
BT502
Medusa and Leshrac made a P1000 payment to the cashier on July 21,
2020. Write queries that will demonstrate this transaction and follows
the tables schema
BEGIN
BEGIN TRANSACTION
COMMIT
END
m
er as
co
eH w
o.
rs e
ou urc
o
aC s
vi y re
ed d
ar stu
is
Th
sh
This study source was downloaded by 100000809080396 from CourseHero.com on 10-20-2021 23:02:09 GMT -05:00
https://www.coursehero.com/file/90559735/03-Handson-Adbasedocx/
John Chester Arevalo 03 Hands-on Activity
BT502
Lina made a full payment to her tuition fee in July 28, 2020. After a
few minutes, the cashier found out that she had mistakenly encoded
the payment to Slark.
BEGIN
BEGIN TRANSACTION
ROLLBACK
BEGIN TRANSACTION
UPDATE Students2 SET Balance = Balance - 15000 WHERE S_ID = 90
INSERT INTO Payment VALUES( 4, CAST(N'2020-07-28' AS Date), CAST(15000.00
AS
Decimal(18, 2)), 90)
COMMIT
m
END
er as
co
eH w
o.
rs e
ou urc
o
aC s
vi y re
ed d
ar stu
is
Th
sh
This study source was downloaded by 100000809080396 from CourseHero.com on 10-20-2021 23:02:09 GMT -05:00
https://www.coursehero.com/file/90559735/03-Handson-Adbasedocx/
John Chester Arevalo 03 Hands-on Activity
BT502
m
er as
co
eH w
o.
rs e
ou urc
o
aC s
vi y re
ed d
ar stu
is
Th
sh
This study source was downloaded by 100000809080396 from CourseHero.com on 10-20-2021 23:02:09 GMT -05:00
https://www.coursehero.com/file/90559735/03-Handson-Adbasedocx/
John Chester Arevalo 03 Hands-on Activity
BT502
Medusa wants to settle her remaining balance through an online
payment. She tried to make a payment on August 1, 2020, through
transferring her funds, but the payment did not successfully proceed.
The system displays a message. “The transaction could not proceed,
the payment that has been received is overpaid. Please try again”.
Write a query that will demonstrate the entire transaction that has
been described.
BEGIN
BEGIN TRANSACTION
DECLARE @balance decimal, @payment decimal
SET @balance = (SELECT Balance FROM Students2 WHERE S_ID = 20)
SET @payment = 15000
m
INSERT INTO Payment VALUES( 5, CAST(N'2020-08-01' AS Date),
er as
CAST(@payment
AS Decimal(18, 2)), 20)
co
eH w
ELSE
ROLLBACK
o.
BEGIN TRANSACTION
rs e
print 'The transaction could not proceed, the payment that has been
received is
ou urc
overpaid. Please try again.'
print CONCAT('Your tuition balance: ', @balance , ' | Your payment: ' ,
@payment)
o
COMMIT
aC s
vi y re
END
ed d
ar stu
is
Th
sh
This study source was downloaded by 100000809080396 from CourseHero.com on 10-20-2021 23:02:09 GMT -05:00
https://www.coursehero.com/file/90559735/03-Handson-Adbasedocx/
John Chester Arevalo 03 Hands-on Activity
BT502
Slark has learned and acquired the discount offered by the school by
the school. He can pay his tuition with less than 15% if he makes full
payment on August 5, 2020. Slark decided to grab the discounted
tuition and make the required payment. Write a query that will
demonstrate the entire transaction that has been described.
BEGIN
BEGIN TRANSACTION
DECLARE @disc DECIMAL, @fullPaymentDISC DECIMAL
SET @disc = (Select Tuition_Fee FROM Students2 WHERE S_ID = 50) * 0.15
SET @fullPaymentDISC = (Select Tuition_Fee FROM Students2 WHERE S_ID = 50)
- @disc
Updating first the tuition fee and the balance of Slark with discount to
know the amount how much slark will pay for his tuition fee
m
@fullPaymentDISC
er as
WHERE S_ID = 50
co
eH w
Since Slark balance is now updated now he can pay the exact amount and
deduct it into his balance
o.
50 rs e
UPDATE Students2 SET Balance = Tuition_Fee - @fullPaymentDISC WHERE S_ID =
ou urc
INSERT INTO Payment VALUES (6, CAST(N'2020-08-05' AS Date),
CAST(@fullPaymentDISC
AS Decimal(18, 2)), 50)
o
It will be all well executed if he decided to take the discount that the
aC s
school offered to him and pay it in exact amount if not, his tuition fee will not
vi y re
update it
IF @fullPaymentDISC = 15300
BEGIN
SAVE TRANSACTION SlarkFullPayment
ed d
END
ar stu
ELSE
ROLLBACK
COMMIT
END
is
Th
sh
This study source was downloaded by 100000809080396 from CourseHero.com on 10-20-2021 23:02:09 GMT -05:00
https://www.coursehero.com/file/90559735/03-Handson-Adbasedocx/
Powered by TCPDF (www.tcpdf.org)