You are on page 1of 10

--CORRECT alter PROCEDURE [dbo].

[ChequeWithdraw] @frmAccNo bigint,@chequeId int, @amount f loat, @date date, @status VARCHAR(150) OUTPUT AS BEGIN IF (exists(SELECT * FROM Customers WHERE CustomerId = (SELECT CustomerId FROM Accounts WHERE AccountNo=@frmAccNo) and [Status] = 'Active')) BEGIN DECLARE @transactionSum FLOAT, @limit FLOAT; SET @transactionSum = (SELECT SUM(TransactionAmount) FROM Transa ctions WHERE AccountNo = @frmAccNo); IF ((@amount+@transactionSum) < (SELECT DebitDayLimit FROM Accou ntTypes WHERE AccTypeId = (SELECT AccTypeId FROM Accounts WHERE AccountNo = @frm AccNo))) BEGIN DECLARE @bal FLOAT; SELECT @bal = Balance FROM Accounts WHERE Accoun tNo = @frmAccNo; IF ((@bal-@amount) > (SELECT MinimumBalance FROM AccountTypes WHERE AccTypeId = (SELECT AccTypeId FROM Accounts WHERE AccountNo = @frmAccNo))) BEGIN IF ((SELECT RemainingLeaves FROM ChequeB ooks WHERE AccountNo=@frmAccNo)>0) BEGIN SET @bal = @bal - @amount; UPDATE Accounts SET Balance = @b al WHERE AccountNo = @frmAccno; INSERT INTO Transactions VALUES (1,@frmAccNo,'UCB',@amount,@bal,getdate(),'Success',2) SET @status = 'Transaction Succe ssfull.'; END ELSE SET @status='Insufficient Cheque Leaves! Transaction Failed!' END ELSE BEGIN SET @bal = @bal - (0.02 * @amount); UPDATE Accounts SET Balance = @bal WHERE AccountNo = @frmAccno; SET @status='Insufficient Funds! Cheque Bounced! Transaction Failed!' END END ELSE SET @status='Daily Withdraw Limit Crossed! Transaction F ailed!' END end DECLARE @_result varchar(100) EXEC ChequeWithdraw 1010001,1,2300,'2013-12-11',@_result output PRINT @_result ------------------------------------------------------------------------CORRECT CREATE PROCEDURE GetChequeBookRequests AS

BEGIN SELECT * FROM ChequeBooks WHERE ChequeBookStatus='Pending' END EXEC GetChequeBookRequests ---------------------------------------------------------------------------CORRECT ALTER PROCEDURE ApproveOrRejectChequeBookRequests @AccountNumber bigint, @Status int AS BEGIN IF @Status=1 BEGIN UPDATE ChequeBooks SET ChequeBookStatus='Approved' WHERE Account No=@AccountNumber END ELSE IF @Status=2 BEGIN UPDATE ChequeBooks SET ChequeBookStatus='Rejected' WHERE Account No=@AccountNumber END END EXEC ApproveOrRejectChequeBookRequests 1111,2 -------------------------------------------------CORRECT ALTER PROCEDURE UpdateCurrentAccountDetails @ContactName varchar(50), @Website varchar(50), @BusinessTypeId int, @BusinessTypeName varchar(50), @LoginId varchar(50), @result binary output AS BEGIN DECLARE @customerid int DECLARE @accountno bigint DECLARE @accounttype varchar(20) SET @customerid=(SELECT CustomerId FROM LoginCredentials WHERE LoginId=@ LoginId) SET @accountno=(SELECT AccountNo FROM Accounts WHERE CustomerId=@custome rid) INSERT INTO CurrentAccounts VALUES(@BusinessTypeName,@BusinessTypeId,@Co ntactName,@accountno,@Website,'Pending'); SET @result=1 END ----------------------------------------------------------CORRECT ALTER PROCEDURE UpdateCustomerDetails @Address varchar(100), @City varchar(50), @State varchar(50), @Country varchar(50), @PhoneNo bigint, @MobileNo bigint, @EmailId varchar(50), @LoginId varchar(50),

@result binary output AS BEGIN DECLARE @customerid int SET @customerid=(SELECT CustomerId FROM LoginCredentials WHERE LoginId=@ LoginId) INSERT INTO Customers VALUES(@customerid,@Address,@City,@State,@Country, @PhoneNo,@MobileNo,@EmailId,'Pending') SET @result=1 END

-----------------------------------------------------------------CORRECT CREATE PROCEDURE GetAccountTypeByLoginId @loginid varchar(50), @accounttype varchar(50) output AS BEGIN SET @accounttype=(SELECT AccTypeName FROM AccountTypes WHERE AccTypeId= (SELECT AccTypeId FROM Accounts WHERE CustomerId=( SELECT CustomerId FROM LoginCredenti als WHERE LoginId=@loginid))) END DECLARE @_accounttype varchar(50) EXECUTE GetAccountTypeByLoginId 'divyasindhuri',@_accounttype output PRINT @_accounttype ----------------------------------------------------------------CORRECT ALTER PROCEDURE StoreChequeRequests @loginid varchar(50), @NumberOfLeaves int, @result binary output AS BEGIN DECLARE @accountnum bigint DECLARE @accounttypeid bigint SET @accountnum=(SELECT AccountNo FROM Accounts WHERE CustomerId=( SELECT CustomerId FROM LoginCredentials WHERE LoginId=@loginid)) SET @accounttypeid=(SELECT AccTypeId FROM Accounts WHERE AccountNo=@accountnum) IF @accounttypeid=1 BEGIN IF (SELECT Balance FROM Accounts WHERE AccountNo=@accountnum)<(5 000+50) SET @result=0 ELSE BEGIN INSERT INTO ChequeBooks values(@accountnum,@NumberOfLeav es,getdate(),@NumberOfLeaves,'Pending') UPDATE Accounts SET Balance=Balance-50 WHERE AccountNo=@ accountnum SET @result=1 END END

IF @accounttypeid=2 OR @accounttypeid=3 BEGIN IF (SELECT Balance FROM Accounts WHERE AccountNo=@accountnum)>50 BEGIN INSERT INTO ChequeBooks values(@accountnum,@NumberOfLeav es,getdate(),@NumberOfLeaves,'Pending') UPDATE Accounts SET Balance=Balance-50 WHERE AccountNo=@ accountnum SET @result=1 END ELSE SET @result=0 END END DECLARE @_result binary EXECUTE StoreChequeRequests Sindhu,20,@_result output PRINT @_result ----------------------------------------------------------------------CORRECT ALTER PROCEDURE GetProfileInfo @loginid varchar(50),@accounttype varchar(50) AS BEGIN DECLARE @custid int DECLARE @acntno bigint SET @custid=(SELECT CustomerId FROM LoginCredentials where LoginId=@logi nid) IF @accounttype='Current' SELECT c.CustomerId,c.[Address],c.City,c.[State],c.Country,c.Pho neNo,c.MobileNo,c.EmailId, ca.BusinessName,ca.BusinessTypeId,ca.ContactName,ca.Website FROM Customers c INNER JOIN Accounts a ON c.CustomerId=a.CustomerId INNER JOIN CurrentAccounts ca ON a.AccountNo=ca.AccountNo WHERE c.CustomerId=@custid AND c.Status='Active' ELSE SELECT c.CustomerId,c.[Address],c.City,c.[State],c.Country,c.Pho neNo,c.MobileNo,c.EmailId, sa.Name,sa.FatherName,sa.Gender,sa.DateOfBirth,sa.CompanyName FROM Customers c INNER JOIN Accounts a ON c.CustomerId=a.CustomerId INNER JOIN SavingsAccounts sa ON a.AccountNo=sa.AccountNo WHERE c.CustomerId=@custid AND c.Status='Active'--@custid END EXECUTE GetProfileInfo 'Dhruva','SavingsCorporate' -----------------------------------------CORRECT ALTER PROCEDURE GetUpdateRequests--RetrieveUpdateRequests AS BEGIN SELECT * FROM (SELECT c.CustomerId as CustId, c.Address, c.City, c.State, c.Country, c.PhoneNo , c.MobileNo, c.EmailId FROM Customers c where Status='Pending') t1 left outer

join (SELECT ca.ContactName, ca.Website,a.CustomerId as CustId FROM CurrentAccounts c a, Accounts a where AccountStatus='Pending' and ca.AccountNo = a.AccountNo) t2 on t1.CustId = t2.CustId END EXEC GetUpdateRequests EXEC RetrieveUpdateRequests ------------------------------------------------CORRECT CREATE PROCEDURE GetAccountCreationRequests AS BEGIN SELECT * FROM (SELECT c.CustomerId as CustId, c.Address, c.City, c.State, c.Country, c.PhoneNo , c.MobileNo, c.EmailId FROM Customers c where Status='New') t1 left outer join (SELECT ca.ContactName, ca.Website,a.CustomerId as CustId FROM CurrentAccounts c a, Accounts a where AccountStatus='New' and ca.AccountNo = a.AccountNo) t2 on t1.CustId = t2.CustId END EXEC GetAccountCreationRequests ------------------------------------------------CORRECT ALTER PROCEDURE ApproveAccountCreationRequests @CustomerId int, @result binary output AS BEGIN DECLARE @accountnum bigint DECLARE @AccountTypeId int SET @accountnum=(SELECT AccountNo FROM Accounts WHERE CustomerId=@Custom erId) SET @AccountTypeId=(SELECT AccTypeId FROM Accounts WHERE CustomerId=@Cus tomerId) UPDATE Customers SET Status='Active' WHERE Status='New' AND CustomerId=@CustomerId; UPDATE LoginCredentials SET UserType='User' WHERE UserType='New' AND CustomerId=@CustomerId; IF @AccountTypeId=3 BEGIN UPDATE CurrentAccounts SET AccountStatus='Active' WHERE AccountStatus='New' AND AccountNo=@accountnum; END SET @result=1 END DECLARE @_result binary EXECUTE ApproveAccountCreationRequests 878,@_result output PRINT @_result -----------------------------------------------

--CORRECT ALTER PROCEDURE RejectAccountCreationRequests AS BEGIN

@CustomerId int, @result binary output

DECLARE @accountnum bigint DECLARE @AccountTypeId int SET @accountnum=(SELECT AccountNo FROM Accounts WHERE CustomerId=@Custom erId) SET @AccountTypeId=(SELECT AccTypeId FROM Accounts WHERE CustomerId=@Cus tomerId) Update Customers SET Status='Rejected' where Status='New' AND CustomerId=@CustomerId; UPDATE LoginCredentials SET UserType='Rejected' WHERE UserType='New' AND CustomerId=@CustomerId; IF @AccountTypeId=3 BEGIN UPDATE CurrentAccounts SET AccountStatus='Rejected' where AccountStatus='New' AND AccountNo=@accountnum; END SET @result=1 END DECLARE @_result binary EXECUTE RejectAccountCreationRequests 878,@_result output PRINT @_result --------------------------------------------------CORRECT ALTER PROCEDURE ApproveUpdateRequests @CustomerId int, @result binary output AS BEGIN DECLARE @accountnum bigint DECLARE @AccountTypeId int SET @accountnum=(SELECT AccountNo FROM Accounts WHERE CustomerId=@Custom erId) SET @AccountTypeId=(SELECT AccTypeId FROM Accounts WHERE CustomerId=@Cus tomerId) Update Customers SET Status='Inactive' where Status='Active' AND CustomerId=@CustomerId; Update Customers SET Status='Active' where Status='Pending' AND CustomerId=@CustomerId; IF @AccountTypeId=3 BEGIN UPDATE CurrentAccounts SET AccountStatus='Inactive' where AccountStatus='Active' AND AccountNo=@accountnum;

UPDATE CurrentAccounts SET AccountStatus='Active' where AccountStatus='Pending' AND AccountNo=@accountnum; END SET @result=1 END DECLARE @_result binary EXECUTE ApproveUpdateRequests 909,@_result output PRINT @_result ---------------------------------------------CORRECT ALTER PROCEDURE RejectUpdateRequests @CustomerId int, @result binary output AS BEGIN DECLARE @accountnum bigint DECLARE @AccountTypeId int SET @accountnum=(SELECT AccountNo FROM Accounts WHERE CustomerId=@Custom erId) SET @AccountTypeId=(SELECT AccTypeId FROM Accounts WHERE CustomerId=@Cus tomerId) Update Customers SET Status='Rejected' where Status='Pending' AND CustomerId=@CustomerId; IF @AccountTypeId=3 BEGIN UPDATE CurrentAccounts SET AccountStatus='Rejected' where AccountStatus='Pending' AND AccountNo=@accountnum; END SET @result=1 END DECLARE @_result binary EXECUTE RejectUpdateRequests 909,@_result output PRINT @_result ---------------------------------------------CORRECT Alter PROCEDURE VerifyPassword @password VARCHAR(50), @loginId varchar(50), @res ult binary OUTPUT AS if exists(select 'true' from LoginCredentials where (LoginId=@loginId and[Passwo rd]=@password)) begin SET @result=1; end else begin Set @result=0; end DECLARE @_result binary

exec verifypassword 'Dhruva' ,'Dhrsuva', @_result output print @_result -----------------------------------------------------ChequeWithDraw-----------------------------------------------------------------------CREATE PROCEDURE ChequeWithdrawal @AccountNo bigint, @Amount float, @Date date, @ChequeId int output, @result binary output AS BEGIN SET NOCOUNT ON; DECLARE @remainingleaves int SET @remainingleaves=(SELECT RemainingLeaves FROM ChequeBooks WHERE Acco untNo=@AccountNo); IF @remainingleaves>0 BEGIN select @bal=[Balance] from [Accounts] where AccountNo=@AccountId END ELSE SET @result=0; --if exists(select 'true' from Cheques where ChequeId=@ChequeId) --declare @bal float; --if exists(select 'true' from Accounts where AccountNo=@AccountId) --begin --select @bal=[Balance] from [Accounts] where AccountNo=@AccountId --set @bal=@bal+@Balance --update [Accounts] set [Balance]=@bal where AccountNo=@AccountId --set @status=1 --end --else --begin --set @status=0 --end END declare @res binary exec CashDeposit 1010003,400,@res output print @res --CashWithDraw-----------------------------------------------------------------------alter PROCEDURE CashWithDraw @AccountId bigint, @Balance float, @status binary output AS BEGIN SET NOCOUNT ON; declare @bal float if exists(select 'true' from Accounts where AccountNo=@AccountId ) begin select @bal=[Balance] from [Accounts] where AccountNo=@AccountId

if exists(select 'true' from Accounts where @bal-500>=@Balance ) begin set @bal=@bal-@Balance update [Accounts] set [Balance]=@bal where AccountNo=@AccountId set @status=1 end else begin set @status=0 end end else begin set @status=0 end END declare @res binary exec CashWithDraw 1010000,500,@res output print @res --CashDeposit---------------------------------------alter PROCEDURE CashDeposit @AccountId bigint, @Balance float, @status binary output AS BEGIN SET NOCOUNT ON; declare @bal float; if exists(select 'true' from Accounts where AccountNo=@AccountId) begin select @bal=[Balance] from [Accounts] where AccountNo=@AccountId set @bal=@bal+@Balance update [Accounts] set [Balance]=@bal where AccountNo=@AccountId set @status=1 end else begin set @status=0 end END declare @res binary exec CashDeposit 1010003,400,@res output print @res -------------------------------------------------------ALTER PROCEDURE UpdateCustomerDetails1 @Address varchar(100), @City varchar(50), @State varchar(50), @Country varchar(50), @PhoneNo bigint, @MobileNo bigint, @EmailId varchar(50), @ContactName varchar(50),

@Website varchar(50), @BusinessTypeId int, @BusinessTypeName varchar(50), @LoginId varchar(50), @result binary output AS BEGIN DECLARE @customerid int DECLARE @accountno bigint DECLARE @accounttype varchar(20) SET @customerid=(SELECT CustomerId FROM LoginCredentials WHERE LoginId=@ LoginId) SET @accountno=(SELECT AccountNo FROM Accounts WHERE CustomerId=@custome rid) SET @accounttype=(SELECT AccTypeName FROM AccountTypes WHERE AccTypeId=( SELECT AccTypeId FROM Accounts WHERE AccountNo=@accountno)) INSERT INTO Customers VALUES(@customerid,@Address,@City,@State,@Country, @PhoneNo,@MobileNo,@EmailId,'Pending') IF @accounttype='Current' INSERT INTO CurrentAccounts VALUES(@BusinessTypeName,@BusinessTy peId,@ContactName,@accountno,@Website,'Pending'); SET @result=1 END

You might also like