Documente Academic
Documente Profesional
Documente Cultură
TransactionFees table so that individual fees are smaller than transaction amount
for any given transaction. In addition, starting with 2013, individual fees for Cash
withdrawal (ATM)-RON transactions cannot exceed 25 RON.
create trigger [dbo].[S2_Task2_prof] on [dbo].[TransactionFees]
for insert,update
as
begin
if exists(select *
from inserted i inner join
[dbo].[AccountTransactions] t on t.[TransactionId]=i.[TransactionId]
where ([FeeAmount]>25 and
[TransactionType]='Cash withdrawal (ATM)- RON'
and year([TransactionDate])>=2013)
or ([Amount]<[FeeAmount])
)
begin
rollback
raiserror('individual fees are smaller than transaction amount for any given transaction.
In addition, starting with 2013, individual fees for Cash withdrawal (ATM)-RON transactions
cannot exceed 25 RON.',
15,2)
end
end
Define a view to display the total transaction amount and total fee amount per
transaction type, both computed by considering transactions in the past 9 months
in case of accounts opened more than 3 years back by bank customers in Bucureti
and Sibiu. Results should be sorted in descending order by the total transaction
amount.
create view [dbo].[S2_Task1_prof]
as
select top 100 percent [TransactionType],sum([Amount]) as TotalAmount,
sum([FeeAmount]) as TotalFeeAmount
from [dbo].[AccountTransactions] a inner join [dbo].[TransactionFees] tf
on a.TransactionId=tf.TransactionId
inner join BankAccounts ba on ba.[AccountId]=a.[AccountId]
inner join [dbo].[AccountOwners] ao on ao.[OwnerPIN]=ba.[OwnerPIN]
where lower([Locality]) in ('bucuresti', 'sibiu')
and datedif(month,[TransactionDate],getdate()) between 0 and 9
and datedif(year,[OpeningDate],getdate())>=3
group by [TransactionType]
order by 2 desc
Define a stored procedure with 2 output parameters which return the total number
of transactions and total fee amount for a certain account and time period, both
specified at execution time.
Define a function which returns the list of transactions and the corresponding (total)
transaction fee amount for the particular type of account with the least transactions
in a month specified as a parameter. In order to illustrate how this function can be
put to use, you are required to create a stored procedure which calls the function
and provides additional information on the accounts involved in transactions (id,
IBAN, owners name).
Table variable
create function [dbo].[S1_Task4_prof] (@pYear smallint, @pMonth tinyint)
returns @t table([TransactionId] int,TotalFee money)
as
begin
with tmp as(
select [AccountType], dense_rank() over(order by count(*)) as Ranking
from [dbo].[BankAccounts] a inner join [dbo].[AccountTransactions] t
on a.[AccountId]=t.[AccountId]
where datepart(month,[TransactionDate])=@pMonth and
datepart(year,[TransactionDate])=@pYear
group by [AccountType]
)
insert into @t
select t.[TransactionId], sum([FeeAmount])
from tmp inner join [dbo].[BankAccounts] a on
tmp.AccountType=a.AccountType
inner join [dbo].[AccountTransactions] t
on t.[AccountId]=a.[AccountId] inner join [dbo].[TransactionFees] f
on f.TransactionId=t.TransactionId
where Ranking=1 and datepart(month,[TransactionDate])=@pMonth and
datepart(year,[TransactionDate])=@pYear
group by t.[TransactionId]
return
end
which calls the function and provides additional information on the accounts
involved in transactions (id, IBAN, Owners name).
create procedure [dbo].[S1_Task4_prof_Part2] @pYear smallint, @pMonth tinyint
as
begin
select f.*,[AccountIBAN],a.[AccountId],[LastName],[FirstName]
from S1_Task4_prof(@pYear, @pMonth) f inner join
[dbo].[AccountTransactions] t on t.[TransactionId]=f.[TransactionId]
inner join [dbo].[BankAccounts] a on a.[AccountId]=t.[AccountId]
inner join [dbo].[AccountOwners] o on o.OwnerPIN=a.[OwnerPIN]
end
Define a stored procedure to insert new records into the TransactionFees table.
When the fee in question is not available in the database it must be inserted into
the corresponding table (Fees) prior to using it in the context of account
transactions. Regardless of the reasons, if this operation fails, then both insert
actions must be cancelled.
end
end try
begin catch
if @@trancount>0 rollback
select error_message(), error_number()
end catch
subject 4
Define a function which returns the list of transactions for the most frequently
performed transaction type during the past N months (N is to be specified at
execution time); the highest fee as well as the lowest should be displayed for each
of the selected transactions. In order to illustrate how this function can be put to
use, you are required to create a stored procedure which calls the function and
provides additional information on the accounts involved in transactions (id, IBAN,
owners name).