sqllearner
Aged Yak Warrior
639 Posts |
Posted - 2006-10-25 : 14:27:12
|
CREATE PROCEDURE [dbo].[usp_dd_collection_refresh_dal] @latest_fd_refresh_dares_download_id INTAS DECLARE @error_int INT DECLARE @sys_error_msg VARCHAR(500) DECLARE @module_name VARCHAR(100) DECLARE @executed_sp_name VARCHAR(500) DECLARE @executed_sp_input_parameters VARCHAR(500) DECLARE @executed_sp_ref_table_name VARCHAR(100) DECLARE @executed_action VARCHAR(10) DECLARE @error_notes VARCHAR(500) DECLARE @computer_name VARCHAR(40) DECLARE @main_sp_name VARCHAR(100) DECLARE @nested_sp_name VARCHAR(500) DECLARE @nested_sp_input_parameters VARCHAR(500) DECLARE @nested_sp_ref_table_name VARCHAR(100) DECLARE @nested_executed_action VARCHAR(10) DECLARE @process_id INT DECLARE @status VARCHAR(50) DECLARE @comment VARCHAR(3000) DECLARE @error_log VARCHAR(2000) DECLARE @user_name VARCHAR(40) DECLARE @latest_dd_coll_refresh_dares_download_id INT/* Stored procedure usp_dd_dares_download_log_i inserts the dares download process log informations to the tbl_dares_download_log table of dares_download database as a part of the daily Dares refresh.*/ SET @main_sp_name='usp_dd_collection_refresh_dal' PRINT 'Stored Procedure Executed - ' + @main_sp_name SET @process_id=2 -- This is for Fidelity-Collection Refresh SET @status='NEW' SET @comment='The dares_download_id = ' + CONVERT(VARCHAR,@latest_fd_refresh_dares_download_id) +' is used to select the data from dares_download database to refresh collection database' SET @user_name='dd_coll_refresh' EXECUTE @error_int= usp_dd_dares_download_log_i @process_id,@status,@comment,@user_name,@latest_dd_coll_refresh_dares_download_id OUTPUT,@nested_sp_name OUTPUT,@nested_sp_input_parameters OUTPUT,@nested_sp_ref_table_name OUTPUT,@nested_executed_action OUTPUT -- Error Handling Section IF (@error_int <> 0 ) BEGIN SET @module_name = 'Dares Download Log Information' GOTO Error_Handler_Section END------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- DECLARE @appraisal_i_refresh_id INT,@appraisal_u_refresh_id INT, @bankruptcy_history_i_refresh_id INT, @borrower_i_refresh_id INT,@borrower_u_refresh_id INT, @borrower_address_i_refresh_id INT,@borrower_address_u_refresh_id INT, @borrower_expense_i_refresh_id INT,@borrower_expense_u_refresh_id INT, @borrower_loan_i_refresh_id INT, @comment_i_refresh_id INT, @corporate_advance_transaction_history_i_refresh_id INT, @delinquency_i_refresh_id INT,@delinquency_u_refresh_id INT, @escrow_balances_i_refresh_id INT,@escrow_balances_u_refresh_id INT, @fees_i_refresh_id INT , @hazard_insurance_i_refresh_id INT,@hazard_insurance_u_refresh_id INT, @investor_i_refresh_id INT,@investor_loan_i_refresh_id INT, @lien_holder_i_refresh_id INT,@lien_holder_u_refresh_id INT, @lien_holder_address_i_refresh_id INT,@lien_holder_address_u_refresh_id INT, @lien_holder_contact_i_refresh_id INT,@lien_holder_contact_u_refresh_id INT, @loan_detail_i_refresh_id INT,@loan_detail_u_refresh_id INT, @loss_mitigation_history_i_refresh_id INT, @mi_company_i_refresh_id INT,@mi_company_u_refresh_id INT, @mi_insurance_i_refresh_id INT, @mi_insurance_u_refresh_id INT, @multi_loan_i_refresh_id INT, @note_i_refresh_id INT, @payment_changes_i_refresh_id INT,@payment_changes_u_refresh_id INT, @payment_change_details_i_refresh_id INT,@payment_change_details_u_refresh_id INT, @payment_history_i_refresh_id INT, @phone_contact_i_refresh_id INT,@phone_contact_u_refresh_id INT, @repayment_plan_i_refresh_id INT,@repayment_plan_u_refresh_id INT, @repayment_plan_details_i_refresh_id INT,@repayment_plan_details_u_refresh_id INT, @stops_and_flags_i_refresh_id INT,@stops_and_flags_u_refresh_id INT, @task_tracking_i_refresh_id INT, @task_tracking_u_refresh_id INT, @tax_details_i_refresh_id INT,@tax_details_u_refresh_id INT, @third_party_i_refresh_id INT,@third_party_u_refresh_id INT, @third_party_address_i_refresh_id INT,@third_party_address_u_refresh_id INT, @type_code_i_refresh_id INT EXECUTE @error_int = usp_dd_coll_refresh_count_info_ids_i @latest_dd_coll_refresh_dares_download_id, @user_name, @appraisal_i_refresh_id OUTPUT,@appraisal_u_refresh_id OUTPUT, @bankruptcy_history_i_refresh_id OUTPUT, @borrower_i_refresh_id OUTPUT,@borrower_u_refresh_id OUTPUT, @borrower_address_i_refresh_id OUTPUT,@borrower_address_u_refresh_id OUTPUT, @borrower_expense_i_refresh_id OUTPUT,@borrower_expense_u_refresh_id OUTPUT, @borrower_loan_i_refresh_id OUTPUT, @comment_i_refresh_id OUTPUT, @corporate_advance_transaction_history_i_refresh_id OUTPUT, @delinquency_i_refresh_id OUTPUT,@delinquency_u_refresh_id OUTPUT, @escrow_balances_i_refresh_id OUTPUT,@escrow_balances_u_refresh_id OUTPUT, @fees_i_refresh_id OUTPUT , @hazard_insurance_i_refresh_id OUTPUT,@hazard_insurance_u_refresh_id OUTPUT, @investor_i_refresh_id OUTPUT,@investor_loan_i_refresh_id OUTPUT, @lien_holder_i_refresh_id OUTPUT,@lien_holder_u_refresh_id OUTPUT, @lien_holder_address_i_refresh_id OUTPUT,@lien_holder_address_u_refresh_id OUTPUT, @lien_holder_contact_i_refresh_id OUTPUT,@lien_holder_contact_u_refresh_id OUTPUT, @loan_detail_i_refresh_id OUTPUT,@loan_detail_u_refresh_id OUTPUT, @loss_mitigation_history_i_refresh_id OUTPUT, @mi_company_i_refresh_id OUTPUT,@mi_company_u_refresh_id OUTPUT, @mi_insurance_i_refresh_id OUTPUT,@mi_insurance_u_refresh_id OUTPUT, @multi_loan_i_refresh_id OUTPUT, @note_i_refresh_id OUTPUT, @payment_changes_i_refresh_id OUTPUT,@payment_changes_u_refresh_id OUTPUT, @payment_change_details_i_refresh_id OUTPUT,@payment_change_details_u_refresh_id OUTPUT, @payment_history_i_refresh_id OUTPUT, @phone_contact_i_refresh_id OUTPUT,@phone_contact_u_refresh_id OUTPUT, @repayment_plan_i_refresh_id OUTPUT,@repayment_plan_u_refresh_id OUTPUT, @repayment_plan_details_i_refresh_id OUTPUT,@repayment_plan_details_u_refresh_id OUTPUT, @stops_and_flags_i_refresh_id OUTPUT,@stops_and_flags_u_refresh_id OUTPUT, @task_tracking_i_refresh_id OUTPUT, @task_tracking_u_refresh_id OUTPUT, @tax_details_i_refresh_id OUTPUT,@tax_details_u_refresh_id OUTPUT, @third_party_i_refresh_id OUTPUT,@third_party_u_refresh_id OUTPUT, @third_party_address_i_refresh_id OUTPUT,@third_party_address_u_refresh_id OUTPUT, @type_code_i_refresh_id OUTPUT, @nested_sp_name OUTPUT,@nested_sp_input_parameters OUTPUT,@nested_sp_ref_table_name OUTPUT,@nested_executed_action OUTPUT -- Error Handling Section IF (@error_int <> 0 ) BEGIN SET @module_name = 'Collection Refresh Count Id Information' GOTO Error_Handler_Section END DECLARE @loan_number varchar(13) DECLARE @processing_fd_dares_download_id INT DECLARE @loop_restriction_id INT DECLARE active_collection_loan_cur CURSOR READ_ONLY FOR SELECT loan_number FROM tbl_active_collection_loans WHERE status='NEW' AND dares_download_id=@latest_fd_refresh_dares_download_id OPEN active_collection_loan_cur FETCH NEXT FROM active_collection_loan_cur INTO @loan_number SET @loop_restriction_id=0 WHILE @@FETCH_STATUS = 0 BEGIN PRINT @loop_restriction_id EXECUTE usp_dd_collection_refresh_transaction_dal @latest_fd_refresh_dares_download_id, @loan_number, @appraisal_i_refresh_id,@appraisal_u_refresh_id, @bankruptcy_history_i_refresh_id , @borrower_i_refresh_id,@borrower_u_refresh_id, @borrower_address_i_refresh_id,@borrower_address_u_refresh_id, @borrower_expense_i_refresh_id,@borrower_expense_u_refresh_id, @borrower_loan_i_refresh_id, @comment_i_refresh_id, @corporate_advance_transaction_history_i_refresh_id, @delinquency_i_refresh_id,@delinquency_u_refresh_id, @escrow_balances_i_refresh_id,@escrow_balances_u_refresh_id, @fees_i_refresh_id , @hazard_insurance_i_refresh_id,@hazard_insurance_u_refresh_id, @investor_i_refresh_id,@investor_loan_i_refresh_id, @lien_holder_i_refresh_id,@lien_holder_u_refresh_id, @lien_holder_address_i_refresh_id,@lien_holder_address_u_refresh_id, @lien_holder_contact_i_refresh_id,@lien_holder_contact_u_refresh_id, @loan_detail_i_refresh_id,@loan_detail_u_refresh_id, @loss_mitigation_history_i_refresh_id, @mi_company_i_refresh_id,@mi_company_u_refresh_id, @mi_insurance_i_refresh_id,@mi_insurance_u_refresh_id, @multi_loan_i_refresh_id, @note_i_refresh_id, @payment_changes_i_refresh_id,@payment_changes_u_refresh_id, @payment_change_details_i_refresh_id,@payment_change_details_u_refresh_id, @payment_history_i_refresh_id, @phone_contact_i_refresh_id,@phone_contact_u_refresh_id, @repayment_plan_i_refresh_id,@repayment_plan_u_refresh_id, @repayment_plan_details_i_refresh_id,@repayment_plan_details_u_refresh_id, @stops_and_flags_i_refresh_id,@stops_and_flags_u_refresh_id, @task_tracking_i_refresh_id,@task_tracking_u_refresh_id, @tax_details_i_refresh_id,@tax_details_u_refresh_id, @third_party_i_refresh_id,@third_party_u_refresh_id, @third_party_address_i_refresh_id,@third_party_address_u_refresh_id, @type_code_i_refresh_id, @user_name PRINT 'Loan Number' + '-' + @loan_number + 'processed' FETCH NEXT FROM active_collection_loan_cur INTO @loan_number SET @loop_restriction_id=@loop_restriction_id+1 PRINT 'No of loans processed - ' + CONVERT(VARCHAR,@loop_restriction_id) END CLOSE active_collection_loan_cur DEALLOCATE active_collection_loan_cur BEGIN SET @status='COMPLETE' EXECUTE @error_int= usp_dd_coll_refresh_count_info_status_u @latest_dd_coll_refresh_dares_download_id,@status,@user_name,@nested_sp_name OUTPUT,@nested_sp_input_parameters OUTPUT,@nested_sp_ref_table_name OUTPUT,@nested_executed_action OUTPUT -- Error Handling Section IF (@error_int <> 0 ) BEGIN SET @module_name = 'Collection Refresh Count Information' GOTO Error_Handler_Section END /* Stored procedure usp_dd_dares_download_log_u updates the dares download process log information to the tbl_dares_download_log table of dares_download database as a part of the daily Dares refresh. Note :- Status - 'COMPLETE' on Sucess */ SET @error_log = 'Refreshed Successfully' EXECUTE @error_int= usp_dd_dares_download_log_u @latest_dd_coll_refresh_dares_download_id,@status,@error_log,@user_name,@nested_sp_name OUTPUT,@nested_sp_input_parameters OUTPUT,@nested_sp_ref_table_name OUTPUT,@nested_executed_action OUTPUT -- Error Handling Section IF (@error_int <> 0 ) BEGIN SET @module_name = 'Dares Download Log Information' GOTO Error_Handler_Section END END/************************************************************************Error Handling Section***********************************************************************************************/SET @error_int = @@errorError_Handler_Section: IF (@error_int <> 0 ) BEGIN SET @executed_sp_name = @main_sp_name + ' --> ' + @nested_sp_name SET @executed_sp_input_parameters = @nested_sp_input_parameters SET @executed_sp_ref_table_name = @nested_sp_ref_table_name SET @executed_action = @nested_executed_action SET @error_notes = 'Unable to ' + @executed_action + ' data in ' + @executed_sp_ref_table_name SET @sys_error_msg =(SELECT DESCRIPTION FROM master..sysmessages WHERE error = @error_int) EXEC dbo.usp_dd_MrErrorHandler @ErrorNo = @error_int, @ErrorMsg = @sys_error_msg, @TableName = @executed_sp_ref_table_name, @CallingSPName = @executed_sp_name, @Parameters = @executed_sp_input_parameters, @ModuleName = @module_name, @ErrorNotes = @error_notes, @ComputerNm = @computer_name RETURN @error_int END ELSE BEGIN RETURN 0 END/***************************************************************************************************************************************************************************************/GOHere "SELECT loan_number FROM tbl_active_collection_loans WHERE status='NEW' AND dares_download_id=@latest_fd_refresh_dares_download_id" is returing 450004 loans and Its being used in the cursor."usp_dd_coll_refresh_count_info_ids_i" is used to update the no of record processed in each tableHow can make into small chunks of 1000 or best solution other than this ? |
 |
|