Files
mmt_sql/onetime/dataloadfunctions/IHT/IHT_EMT_STD_ODS.sql
2021-07-02 08:40:37 +00:00

92 lines
2.7 KiB
PL/PgSQL
Executable File

drop function if exists staging2.fn_IHTEMT_STD_TRX;
CREATE OR REPLACE FUNCTION staging2.fn_IHTEMT_STD_TRX(p_client_id int,p_function_id int, p_file_mnemonic text,
p_file_sheet_mnemonic text, p_file_syspk int)
RETURNS void
LANGUAGE plpgsql
AS $function$
declare __test_instance_id int;
declare __client_id int :=p_client_id;
declare __function_id int :=p_function_id;
declare __file_mnemonic text :=p_file_mnemonic;
declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic;
declare __file_syspk int :=p_file_syspk;
declare __make text;
declare __model text;
declare err_state text;
declare err_msg text;
declare err_detail text;
declare err_hint text;
declare err_context text;
declare _error int;
declare __test_master_id int;
declare __test_instance_tractor_id int;
begin
__file_syspk := p_file_syspk;
/************************************************************
Function Name:fn_IHTEMT_STD_TRX
Function Desc: This function populates data into ODS
File Format: IHTEMT
Sheet Format: IHTEMT_STD
Creation Date:
Updation Date:
Author: compegence team
Function Call: select staging2.fn_IHTEMT_STD_TRX()
***************************************************************/
insert into transactional.iht_steering_effort_raw_data
(
client_id,
function_id,
file_syspk,
file_mnemonic,
file_sheet_mnemonic,
tractor_make,
tractor_model,
time_sec,
steering_anglel,
effort_kg
)
select
client_id,
function_id,
file_syspk,
file_mnemonic,
file_sheet_mnemonic,
make,model,
time_s::numeric,
steering_angle ::numeric,
effort ::numeric
from staging2.IHTEMT_STD_RAW_Data_Block where trx_record=1;
select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk;
select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk;
select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk;
select syspk from transactional.test_master into __test_master_id where test_type ='In House';
select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk;
update transactional.test_instance
set test_master_id =__test_master_id,
test_tractor_id =__test_instance_tractor_id
where file_syspk=__file_syspk;
update transactional.test_instance_tractor_info
set test_instance_id=__test_instance_id,
tractor_model =__model,
tractor_make=__make
where file_syspk=__file_syspk;
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_IHTEMT_STD_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success');
end
$function$
;