- ORA-01407: cannot update ("PSOWNER"."PS_VCHR_LINE_STG"."CLASS_FLD") to NULL Failed SQL stmt: UPDATE - peoplesoft

Error Message:- ORA-01407: cannot update ("PSOWNER"."PS_VCHR_LINE_STG"."CLASS_FLD") to NULL Failed SQL stmt: UPDATE
When I am generating the report it is saying NO Success in Peoplesoft.
Below is the code for the Update statement.
Please help me how to overcome this problem.
UPDATE %Table(VCHR_LINE_STG) A
SET A.CLASS_FLD = (
SELECT SUBSTR(DCP_FLD49
,3
,4)
FROM %Table(DCP_AP11_TMP2)
WHERE VCHR_BLD_KEY_C1 = A.VCHR_BLD_KEY_C1
AND DCP_FLD34= A.VOUCHER_LINE_NUM),A.BUSINESS_UNIT =(
SELECT D.CF_ATTRIB_VALUE
FROM %Table(CF_ATTRIB_TBL) D
, %Table(DEPT_TBL) E
WHERE ( D.EFFDT = (
SELECT MAX(D_ED.EFFDT)
FROM %Table(CF_ATTRIB_TBL) D_ED
WHERE D.SETID = D_ED.SETID
AND D.CHARTFIELD_VALUE = D_ED.CHARTFIELD_VALUE
AND D_ED.EFFDT <= SYSDATE)
AND E.EFFDT=D.EFFDT
AND D.CHARTFIELD_VALUE = (
SELECT M.DCP_FLD41
FROM %Table(DCP_AP11_TMP2) M
WHERE M.VCHR_BLD_KEY_C1 = A.VCHR_BLD_KEY_C1
AND M.DCP_FLD34= A.VOUCHER_LINE_NUM)
AND D.SETID = E.SETID
AND D.SETID = 'DCPID'
AND D.CF_ATTRIBUTE='AP_BUSN_UNIT'
AND E.EFFDT = (
SELECT MAX(E_ED.EFFDT)
FROM %Table(DEPT_TBL) E_ED
WHERE E.SETID = E_ED.SETID
AND E.DEPTID = E_ED.DEPTID
AND E_ED.EFFDT <= SYSDATE)
AND E.DEPTID = D.CHARTFIELD_VALUE
AND E.SETID = D.SETID
AND E.EFF_STATUS='A')),A.BUSINESS_UNIT_GL=(
SELECT D.CF_ATTRIB_VALUE
FROM %Table(CF_ATTRIB_TBL) D
, %Table(DEPT_TBL) E
WHERE ( D.EFFDT = (
SELECT MAX(D_ED.EFFDT)
FROM %Table(CF_ATTRIB_TBL) D_ED
WHERE D.SETID = D_ED.SETID
AND D.CHARTFIELD_VALUE = D_ED.CHARTFIELD_VALUE
AND D_ED.EFFDT <= SYSDATE)
AND E.EFFDT=D.EFFDT
AND D.CHARTFIELD_VALUE = (
SELECT M.DCP_FLD41
FROM %Table(DCP_AP11_TMP2) M
WHERE M.VCHR_BLD_KEY_C1 = A.VCHR_BLD_KEY_C1
AND M.DCP_FLD34= A.VOUCHER_LINE_NUM)
AND D.SETID = E.SETID
AND D.SETID = 'DCPID'
AND D.CF_ATTRIBUTE='GL_BUSN_UNIT'
AND E.EFFDT = (
SELECT MAX(E_ED.EFFDT)
FROM %Table(DEPT_TBL) E_ED
WHERE E.SETID = E_ED.SETID
AND E.DEPTID = E_ED.DEPTID
AND E_ED.EFFDT <= SYSDATE)
AND E.DEPTID = D.CHARTFIELD_VALUE
AND E.SETID = D.SETID
AND E.EFF_STATUS='A'))
WHERE EXISTS (
SELECT 'X'
FROM %Table(DCP_AP11_TMP2)
WHERE VCHR_BLD_KEY_C1 = A.VCHR_BLD_KEY_C1
AND VOUCHER_LINE_NUM = A.VOUCHER_LINE_NUM)
Above is the code for the Update statement in App engine.
Please help me how to overcome this problem.
Thanks in Advance.

The sub-selects populating each field are not returning values so the database is trying to update the field to NULL. In PeopleSoft null values are not allowed in character fields. A field with no value needs to be set to a single space, like ' '.
You will need to wrap each sub-select with a COALESCE() function, with a non-null alternative option if the sub-select does not return a value. Character fields need to be set to ' ', numbers to 0 if no values returned. Date fields can be null. Here is an example using the first few lines of the code provided.
UPDATE %Table(VCHR_LINE_STG) A
SET A.CLASS_FLD =
COALESCE(
(SELECT SUBSTR(DCP_FLD49,3,4)
FROM %Table(DCP_AP11_TMP2)
WHERE VCHR_BLD_KEY_C1 = A.VCHR_BLD_KEY_C1
AND DCP_FLD34= A.VOUCHER_LINE_NUM), ' ')
, A.BUSINESS_UNIT_GL=(SELECT
...

Related

MS SQL Case in Where Clause testing against NULL or Argument

I have a query against a UDF where I want to allow the user to pass in either ALL or a specific EType.
If they pass in ALL, I want to accept all ETypes where it is not null.
I have searched thru SO for examples and not seem to meet my particular situation.
Where am I going wrong?
Declare
#company varchar(4),
#charge_cov bit,
#EType varchar(8);
set #company = '123'
set #charge_cov =1
set #EType = 'ALL'
select e.emp_id,
dbo.format_emp_number(pd.EN) as EN,
dbo.format_emp_number(pd.MEN) as MEN,
pd.EType
from dbo.employee_payroll_data(NULL) pd
inner join employee e on (e.emp_id=pd.emp_id)
where pd.EType = case when #EType='ALL' then pd.EType
else #EType ) END
and pd.EType is not null
and e.emp_number is not null
and e.charge_cov = 1
and lc.pr_co_code = #company
Try below code:
WHERE (((1 = (CASE WHEN #EType = 'ALL' THEN 1 ELSE 0 END)))
OR ((pd.Etype = (CASE WHEN #EType <> 'ALL' THEN #EType ELSE '' END))))
AND pd.Etype IS NOT NULL

Select query taking lot of time to execute

I have this query in my application
SELECT
/*+ parallel (4) */
a.orgkey AS cifid,
a.strfield19 AS old_cif_id,
a.cust_first_name,
a.cust_middle_name,
a.cust_last_name,
a.primary_sol_id AS sol_id,
(
SELECT lang.localetext
FROM crmuser.categories cat,
crmuser.category_lang lang
WHERE cat.categoryid=lang.categoryid
AND cat.categorytype= 'PERSONSALUTATION'
AND cat.bank_id =
(
SELECT bank_id
FROM migadm.migr_det)
AND lang.bank_id =
(
SELECT bank_id
FROM migadm.migr_det)
AND cat.value= a.salutation) AS saluatation,
a.segmentation_class AS segmentation_class,
CASE
WHEN corp_id IS NULL THEN
(
SELECT lang.localetext
FROM crmuser.categories cat,
crmuser.category_lang lang
WHERE cat.categoryid=lang.categoryid
AND cat.categorytype= 'SEGMENTATION_CLASS'
AND cat.bank_id =
(
SELECT bank_id
FROM migadm.migr_det)
AND lang.bank_id =
(
SELECT bank_id
FROM migadm.migr_det)
AND cat.value= a.segmentation_class)
ELSE
(
SELECT lang.localetext
FROM crmuser.categories cat,
crmuser.category_lang lang
WHERE cat.categoryid=lang.categoryid
AND cat.categorytype= 'CORP_SEGMENTATION_CLASS'
AND cat.bank_id =
(
SELECT bank_id
FROM migadm.migr_det)
AND lang.bank_id =
(
SELECT bank_id
FROM migadm.migr_det)
AND cat.value= a.segmentation_class)
END AS segmentation_desc,
a.subsegment AS subsegment,
CASE
WHEN corp_id IS NULL THEN
(
SELECT lang.localetext
FROM crmuser.categories cat,
crmuser.category_lang lang
WHERE cat.categoryid=lang.categoryid
AND cat.categorytype= 'SUB_SEGMENT'
AND cat.bank_id =
(
SELECT bank_id
FROM migadm.migr_det)
AND lang.bank_id =
(
SELECT bank_id
FROM migadm.migr_det)
AND cat.value= a.subsegment)
ELSE
(
SELECT lang.localetext
FROM crmuser.categories cat,
crmuser.category_lang lang
WHERE cat.categoryid=lang.categoryid
AND cat.categorytype= 'CORP_SUB_SEGMENT'
AND cat.bank_id =
(
SELECT bank_id
FROM migadm.migr_det)
AND lang.bank_id =
(
SELECT bank_id
FROM migadm.migr_det)
AND cat.value= a.subsegment)
END AS subsegment_desc,
CASE
WHEN a.corp_id IS NULL THEN a.strfield10
ELSE c.struserfield4
END AS reserve_bank_code,
CASE
WHEN a.corp_id IS NULL THEN a.strfield11
ELSE c.struserfield5
END AS form50_code,
a.sector AS pri_sic_code,
a.subsector AS sec_sic_code,
CASE
WHEN a.corp_id IS NULL THEN a.struserfield3
ELSE c.struserfield3
END AS kyc_indicator,
a.defaultaddresstype AS defaultaddresstype,
b.address_line1,
b.address_line2,
b.address_line3,
CASE
WHEN a.corp_id IS NULL THEN
(
SELECT (ad.address_line1
||' '
||ad.address_line2
||' '
||ad.address_line3)
FROM crmuser.address ad
WHERE a.orgkey=ad.orgkey
AND ad. preferredaddress='Y'
AND
(
SELECT migration_date
FROM migadm.migr_det) BETWEEN ad.start_date AND ad.end_date)
ELSE
(
SELECT (ad.address_line1
||' '
||ad.address_line2
||' '
||ad.address_line3)
FROM crmuser.address ad
WHERE a.orgkey=ad.orgkey
AND ad.preferredaddress='Y' and
(
SELECT migration_date
FROM migadm.migr_det) BETWEEN ad.start_date AND ad.end_date)
END AS postal_adress,
b.zip AS postal_code,
a.gender AS gender,
a.cust_dob AS date_of_birth,
(
SELECT p.email
FROM crmuser.phoneemail p
WHERE p.orgkey = a.orgkey
AND p.preferredflag='Y'
AND phoneoremail='EMAIL'
AND ROWNUM =1) email_id,
(
SELECT p.phonenocountrycode
FROM crmuser.phoneemail p
WHERE p.orgkey = a.orgkey
AND p.preferredflag='Y'
AND phoneoremail='PHONE'
AND ROWNUM =1) AS phone_cntry_code,
(
SELECT p.phonenocitycode
FROM crmuser.phoneemail p
WHERE p.orgkey = a.orgkey
AND p.preferredflag='Y'
AND phoneoremail='PHONE'
AND ROWNUM =1) AS phone_city_code,
(
SELECT '+'
|| p.phonenocountrycode
|| '('
|| p.phonenocitycode
|| ')'
|| p.phonenolocalcode
FROM crmuser.phoneemail p
WHERE p.orgkey = a.orgkey
AND p.preferredflag = 'Y'
AND phoneoremail='PHONE') phone_no,
--CASE WHEN (SELECT COUNT(1) FROM crmuser.miscellaneousinfo m WHERE a.orgkey=m.orgkey and type = 'CURRENCY') = 1 THEN (SELECT strtext10 FROM crmuser.miscellaneousinfo m WHERE a.orgkey=m.orgkey and type = 'CURRENCY')
-- WHEN (SELECT COUNT(1) FROM crmuser.corpmiscellaneousinfo m WHERE a.orgkey=m.orgkey and type = 'CURRENCY') = 1 THEN (SELECT str1 FROM crmuser.corpmiscellaneousinfo m WHERE a.orgkey=m.orgkey and type = 'CURRENCY')
-- ELSE
migadm.getcurrencies(a.orgkey)
--END
AS crncy_code,
CASE
WHEN a.corp_id IS NULL THEN a.struserfield15
ELSE c.struserfield6
END AS wht_indicator,
a.cust_swift_code_desc AS cust_swift_code_desc,
customernreflg AS customernreflg,
(
SELECT employerid
FROM crmuser.miscellaneousinfo s
WHERE s.orgkey = a.orgkey
AND TYPE ='CURRENT_EMPLOYMENT') AS group_number,
(
SELECT strtext4
FROM crmuser.miscellaneousinfo s
WHERE s.orgkey = a.orgkey
AND TYPE ='CURRENT_EMPLOYMENT' ) AS employment_details,
--(select EMPLOYERSNAME from crmuser.DEMOGRAPHIC s where s.orgkey = a.orgkey ) AS employment_details,
(
SELECT employeeid
FROM crmuser.miscellaneousinfo s
WHERE s.orgkey = a.orgkey
AND TYPE ='CURRENT_EMPLOYMENT' ) AS employeeid,
--(select EMPLOYERID from crmuser.MISCELLANEOUSINFO s where s.orgkey = a.orgkey ) AS employerid,
a.manager AS manager,
CASE
WHEN a.corp_id IS NULL THEN d.annual_salary_income
ELSE c.average_annualincome
END AS annual_income,
c.registration_number
FROM crmuser.corporate c
right join crmuser.address b
ON b.orgkey=c.corp_key
right join crmuser.accounts a
ON b.orgkey=a.orgkey
left join crmuser.demographic d
ON a.orgkey=d.orgkey
WHERE a.bank_id =
(
SELECT bank_id
FROM migadm.migr_det)
AND a.entity_cre_flag = 'Y'
AND b.preferredaddress = 'Y'
It takes more than 20 minutes to give results. Can someone please help me in tuning this query. I don't have any idea about sql.
I can give the explain plan needed but I don't know how to copy here the 111 rows from plan table

MSDAX 2012 Onhand Calculation from InventSum & InventTrans tables

I have used the below query to calculate the onhand quantity from InventTrans table but that onhand does not match with the AvailPhysical and/or PhysicalInvent of InventSum table. I have tried matching with other quantities as well but onhand is not matching. Please guide me what am i missing here
SELECT T1.ITEMID AS ITEMID
,T1.QTY
,T1.INVENTDIMID AS INVENTDIMID
,DATEDIFF(dd, T3.TRANSDATE, getdate()) AS Age
,t19.price as RetailPrice
,t1.CurrencyCode AS CurrencyKey
,T1.DATAAREAID AS DATAAREAID
,T1.PARTITION AS PARTITION
FROM INVENTTRANS T1
LEFT JOIN INVENTTRANSORIGIN T2 ON (
T1.INVENTTRANSORIGIN = T2.RECID
AND (T1.DATAAREAID = T2.DATAAREAID)
AND (T1.PARTITION = T2.PARTITION)
)
INNER JOIN INVENTTRANSPOSTING T3 ON (
(
(
(
T1.VOUCHERPHYSICAL = T3.VOUCHER
AND (T1.DATAAREAID = T3.DATAAREAID)
AND (T1.PARTITION = T3.PARTITION)
)
)
AND (
T1.DATEPHYSICAL = T3.TRANSDATE
AND (T1.DATAAREAID = T3.DATAAREAID)
AND (T1.PARTITION = T3.PARTITION)
)
)
AND (
T1.INVENTTRANSORIGIN = T3.INVENTTRANSORIGIN
AND (T2.DATAAREAID = T3.DATAAREAID)
AND (T2.PARTITION = T3.PARTITION)
)
) and t3.INVENTTRANSPOSTINGTYPE in (0)
LEFT JOIN INVENTDIM t4 ON (
t4.inventdimid = t1.inventdimid
AND t4.PARTITION = t1.PARTITION
AND t4.dataareaid = t1.dataareaid
)
LEFT OUTER JOIN INVENTTABLEMODULE T19 ON T19.ItemID = T1.ItemID AND T19.DataAreaID = T1.DataAreaID and T19.Partition = T1.Partition AND T19.MODULETYPE=0
LEFT OUTER JOIN INVENTTABLE T20 ON T1.ITEMID = T20.ITEMID AND T1.DATAAREAID = T20.DATAAREAID
where T20.ITEMTYPE <> 2
Any help would be greatly appreciated.

Query filter assign sub query to one field value

I have stuck in this issue from the last two days.
Please help.
I want to assign the following query .
$qr = "( select subconfigcode.field_subconfigcode_value AS configcode FROM node node LEFT JOIN field_data_field_select_parent_configuratio select_parent_configuratio ON node.nid = select_parent_configuratio.entity_id AND (select_parent_configuratio.entity_type = node AND select_parent_configuratio.deleted = 0) LEFT JOIN node select_parent_configuratio_node ON select_parent_configuratio.field_select_parent_configuratio_nid = select_parent_configuratio_node.nid LEFT JOIN field_data_field_subconfigcode subconfigcode ON select_parent_configuratio_node.nid = subconfigcode.entity_id AND (subconfigcode.entity_type = 'node' AND subconfigcode.deleted = '0') WHERE (( (select_parent_configuratio.field_select_parent_configuratio_nid = node_field_data_field_select_parent_configuratio.nid) )AND(( (node.status = '1') AND (node.type IN ('offering')) ))) ORDER BY node.created DESC, configcode ASC LIMIT 1 OFFSET 0)";
to
one view's field value.
I have used the following code.
function general_views_query_alter(&$view, &$query) {
$qr = " ( select subconfigcode.field_subconfigcode_value AS configcode FROM node node LEFT JOIN field_data_field_select_parent_configuratio select_parent_configuratio ON node.nid = select_parent_configuratio.entity_id AND (select_parent_configuratio.entity_type = node AND select_parent_configuratio.deleted = 0) LEFT JOIN node select_parent_configuratio_node ON select_parent_configuratio.field_select_parent_configuratio_nid = select_parent_configuratio_node.nid LEFT JOIN field_data_field_subconfigcode subconfigcode ON select_parent_configuratio_node.nid = subconfigcode.entity_id AND (subconfigcode.entity_type = 'node' AND subconfigcode.deleted = '0') WHERE (( (select_parent_configuratio.field_select_parent_configuratio_nid = node_field_data_field_select_parent_configuratio.nid) )AND(( (node.status = '1') AND (node.type IN ('offering')) ))) ORDER BY node.created DESC, configcode ASC LIMIT 1 OFFSET 0)";
$query->add_where(1, "node_field_data_field_select_parent_configuratio__field_data_field_subconfigcode.field_subconfigcode_value", $qr);
}
But, it is returning the following where query.
where node_field_data_field_select_parent_configuratio__field_data_field_subconfigcode.field_subconfigcode_value = '( select subconfigcode.field_subconfigcode_value AS configcode FROM node node LEFT JOIN field_data_field_select_parent_configuratio select_parent_configuratio ON node.nid = select_parent_configuratio.entity_id AND (select_parent_configuratio.entity_type = node AND select_parent_configuratio.deleted = 0) LEFT JOIN node select_parent_configuratio_node ON select_parent_configuratio.field_select_parent_configuratio_nid = select_parent_configuratio_node.nid LEFT JOIN field_data_field_subconfigcode subconfigcode ON select_parent_configuratio_node.nid = subconfigcode.entity_id AND (subconfigcode.entity_type = \'node\' AND subconfigcode.deleted = \'0\') WHERE (( (select_parent_configuratio.field_select_parent_configuratio_nid = node_field_data_field_select_parent_configuratio.nid) )AND(( (node.status = \'1\') AND (node.type IN (\'offering\')) ))) ORDER BY node.created DESC, configcode ASC LIMIT 1 OFFSET 0) ')
I want to get query without the single quote assigned for sub query and remove extra slashed added to each value.
Please help.
Answer :
Direct query is not applicable for assignment purpose in the add_where condition.
For that, I have generated the query object using.
function general_views_query_alter(&$view, &$query) {
$subQuery = db_select('node', 'node'); $subQuery->leftJoin('field_data_field_select_parent_configuratio', 'select_parent_configuratio ', 'node.nid = select_parent_configuratio .entity_id');
$subQuery->condition('select_parent_configuratio.entity_type', 'node', '=');
$subQuery->condition('select_parent_configuratio.deleted', '0', '=');
$subQuery->leftJoin('node', 'select_parent_configuratio_node', 'select_parent_configuratio.field_select_parent_configuratio_nid = select_parent_configuratio_node.nid');
$subQuery->leftJoin('field_data_field_subconfigcode', 'subconfigcode', 'select_parent_configuratio_node.nid = subconfigcode.entity_id');
$subQuery->condition('subconfigcode.entity_type', 'node', '=');
$subQuery->condition('subconfigcode.deleted', '0', '=');
$subQuery->where("select_parent_configuratio.field_select_parent_configuratio_nid = node_field_data_field_select_parent_configuratio.nid");
$subQuery->condition('node.status', "1", '=');
$subQuery->condition('node.type', array('offering'), 'IN');
$subQuery->orderBy('configcode');
$subQuery->addField('subconfigcode', 'field_subconfigcode_value', 'configcode');
//$subQuery->range(0, 1);
$query->add_where($group,'node_field_data_field_select_parent_configuratio__field_data_field_subconfigcode.field_subconfigcode_value',$subQuery,'in');
}
Using this, I am able to generate it the query and assignment to value of the variable.

combine multiple queries into single query

I have 2 queries and calling a function 2 times I need call the function one time only based on msg_sys_no count and msg_trans_type.
please find the queries mentioned below and provide me the solution for merging into single.
SELECT COUNT(DISTINCT b1.msg_sys_no) INTO A
FROM tra_message b1
WHERE TO_CHAR(b1.msg_when_created,'YYYY-MM-DD') = in_start_date
AND b1.msg_service_provider = in_svc_provider
AND b1.msg_trans_type = 'TRADE1'
AND get_transaction_status_func(b1.msg_sys_no, b1.msg_trans_type) = 'S';
SELECT COUNT(DISTINCT b1.msg_sys_no) INTO B
FROM tra_message b1
WHERE TO_CHAR(b1.msg_when_created,'YYYY-MM-DD') = in_start_date
AND b1.msg_service_provider = in_svc_provider
AND b1.msg_trans_type = 'TRADE2'
AND get_transaction_status_func(b1.msg_sys_no, b1.msg_trans_type) = 'S';
What about something like this:
WITH tra_data
AS (SELECT *
FROM tra_message
WHERE TO_CHAR (msg_when_created, 'YYYY-MM-DD') = in_start_date
AND msg_service_provider = in_svc_provider
AND get_transaction_status_func (msg_sys_no, msg_trans_type) =
'S')
SELECT COUNT (*)
FROM tra_data
WHERE msg_trans_type = 'TRADE1'
UNION
SELECT COUNT (*)
FROM tra_data
WHERE msg_trans_type = 'TRADE2'
The problem is your AND b1.msg_trans_type IN ('TRADE1','TRADE2') condition.
Try something like this:
select COUNT(DISTINCT a) TRADE1,
COUNT(DISTINCT b) TRADE2
into A,B
from (
select case when b1.msg_trans_type = 'TRADE1'
then b1.msg_sys_no
else null end as a,
case when b1.msg_trans_type = 'TRADE2'
then b1.msg_sys_no
else null end as b
FROM tra_message b1
WHERE TO_CHAR(b1.msg_when_created,'YYYY-MM-DD') = in_start_date
AND b1.msg_service_provider = in_svc_provider
AND b1.msg_trans_type IN ('TRADE1','TRADE2')
AND get_transaction_status_func(b1.msg_sys_no, b1.msg_trans_type) = 'S'
);

Resources