Unable to retrieve Data Oracle Fusion BI Publisher - sql

1.Main Code:
SELECT
iodv.organization_id,
iodv.organization_name,
mil.SUBINVENTORY_CODE subinventory_name,
mil.inventory_location_id locator_id,
mil.segment11 || '.' || mil.segment12 || '.' || mil.segment13 locator_name
FROM
inv_item_locations mil,
inv_organization_definitions_v iodv
WHERE
1 = 1
and iodv.organization_id = mil.organization_id
and iodv.Organization_Code = ':Organizations'
and mil.SUBINVENTORY_CODE = ':p_Subinventories'
Parameter p_SubInventories:
select
distinct
iil.Subinventory_code
from
inv_item_locations iil,
INV_ORG_PARAMETERS iop
where
1=1
and iil.ORGANIZATION_ID=iop.ORGANIZATION_ID
and iop.ORGANIZATION_CODE= :Organizations
Parameter for Organizations:
select distinct organization_code from inv_org_parameters
Unable to retrieve data with the above query in Data Model # Oracle BI Publisher......

LEFT JOIN here
SELECT
iodv.organization_id,
iodv.organization_name,
mil.SUBINVENTORY_CODE subinventory_name,
mil.inventory_location_id locator_id,
mil.segment11 || '.' || mil.segment12 || '.' || mil.segment13 locator_name
FROM
inv_item_locations mil
LEFT JOIN
inv_organization_definitions_v iodv
ON
iodv.organization_id = mil.organization_id
WHERE 1 = 1
AND iodv.Organization_Code = ':Organizations'
AND mil.SUBINVENTORY_CODE = ':p_Subinventories'

I would have thought the single apostrophe was problem, but maybe removing the inner join also helps.
It's worth noting the LEFT JOIN could be applied using using PL SQL Outer Join Operator (+). See adjustment to Ops main code below
SELECT
iodv.organization_id,
iodv.organization_name,
mil.SUBINVENTORY_CODE subinventory_name,
mil.inventory_location_id locator_id,
mil.segment11 || '.' || mil.segment12 || '.' || mil.segment13 locator_name
FROM
inv_item_locations mil,
inv_organization_definitions_v iodv
WHERE
1 = 1
and iodv.organization_id (+) = mil.organization_id ----
and iodv.Organization_Code = ':Organizations'
and mil.SUBINVENTORY_CODE = ':p_Subinventories'

Related

PostgreSQL - I have a Syntax error in my SUBSTRING query

I'm trying to make use of the SUBSTRING() function to extract a substring from vm.location_path, starting at the second character and ending at the position of the ']' character, minus two.
I want to extract the text between the square brackets ([]) in vm.location_path but I'm hitting a syntax error.
SELECT
'UPDATE vm SET dstore_moref = ''' || datastore_inv.moref || ''' WHERE id = ''' || vm.id || ''';'
FROM
vm
INNER JOIN vapp_vm ON vapp_vm.svm_id = vm.id
INNER JOIN vm_inv ON vm_inv.moref = vm.moref
INNER JOIN datastore_inv ON datastore_inv.vc_display_name =(
SUBSTRING(
vm.location_path,
2,
POSITION(']',
vm.location_path) - 2
)
)
WHERE
vm.dstore_moref IS NULL AND vm_inv.is_deleted IS FALSE
GROUP BY datastore_inv.moref, vm.id;
SQL Error [42601]: ERROR: syntax error at or near ","
Position: 370
Error position: line: 11 pos: 369
It's between the comma at the end of
POSITION(']',
and
vm.location_path) - 2
What am I not seeing?
This is for vCloud Director. I am trying to get a print out of all VMs that are NULL.
The syntax is POSITION(search_string in main_string) with IN Keyowrd instead of ,
SELECT
'UPDATE vm SET dstore_moref = ''' || datastore_inv.moref || ''' WHERE id = ''' || vm.id || ''';'
FROM
vm
INNER JOIN vapp_vm ON vapp_vm.svm_id = vm.id
INNER JOIN vm_inv ON vm_inv.moref = vm.moref
INNER JOIN datastore_inv ON datastore_inv.vc_display_name =(
SUBSTRING(
vm.location_path,
2,
POSITION(']' IN vm.location_path) - 2
)
)
WHERE
vm.dstore_moref IS NULL AND vm_inv.is_deleted IS FALSE
GROUP BY datastore_inv.moref, vm.id;

Condition Joins With many to many relationships

I am working claims data and repricing the claims according to a different fee schedule. So I have two tables. The claims and fschedule. In this case, the repricing boils down to CPT_Code and Modifier. So I am conditionally joining them on
claims.CPT = fschedule.CPT
AND
claims.mod = fschedule.mod
Here is how the fschedule looks:
CPT || Modifier || Price
77325 || 26 || 73.25
77325 || TC || 52.77
77325 || XX || 101.21
77333 || XX || 12.31
However, my problem is that claims table may have:
CPT || Modifier
77333 || TC
But the fschedule may have 77333 but not with a TC or 26 only XX. So I want the tables to join on both
claims.CPT = fschedule.CPT
AND
claims.mod = f.schedule.mod
but if there is no match in the fschedule then I want it to match when fschedule modifier XX
I am trying to conditionally join the two tables using case statements.
FROM
claims as c
LEFT JOIN
fschedule as f
ON
CASE WHEN c.mod IN ('TC','26') THEN
CASE WHEN f.mod IN ('TC','26') AND c.cpt= f.cpt AND c.mod = f.mod THEN c.cpt = f.cpt AND c.mod = f.mod
WHEN f.mod NOT IN ('TC','26') AND c.cpt= f.cpt AND c.mod <> f.mod THEN c.cpt = f.cpt AND c.mod <> f.mod
END
WHEN c.mod NOT IN ('TC','26') AND f.mod NOT IN ('TC','26') THEN c.cpt = f.cpt AND c.mod = f.mod
END;
I need to use a conditional left join like:
Claims as c
LEFT JOIN
fschedule as f
ON
c.CPT = f.CPT
AND
c.mod = f.mod
However, if the claims table has:
CPT || Modifier || Paid
77333 || TC || 7.88
But the fschedule only has:
CPT || Modifier || Price
77333 || XX || 12.31
I need the claims table to still output the price of 12.31 found in the fschedule table. The XX modifier means no modifier exists.
Claims table before joining it to the fschedule table has 22,124 rows of data. After joining them with my current code the table outputs 25,283 rows of data. I need the output to stay 22,124.
In short, I need the two tables to join together on both:
c.cpt = f.cpt
AND
c.mod = f.mod
but if the claims table has a CPT code and modifier, but the fschedule only has the CPT code and no modifier match, then I need to force the fschedule to output the the price with the modifier XX since it does not have TC or 26 modifier.
Thank you for your help.
*************Updated issue**************
Claims table:
CPT || Mod || Paid
77067 || TC || 83.10
Fees Table
CPT || Mod || Price
77067 || 26 || 76.23
77067 || XX || 103.01
So even though the claims table has a modifier TC but fees table has the code but not the modifier, I still want it to connect on the claims table using the fees table when the modifier = XX. So I would want the end result looking like:
CPT || Mod || Paid || Fees_Price || Fees_Mod
77067 || TC || 83.10 || 103.01 || XX
As of right now this is the output:
CPT || Mod || Paid || Fees_Price || Fees_Mod
77067 || TC || 83.10 || ||
Thanks
A much simpler ON condition can do the trick:
ON (c.CPT = f.CPT AND c.mod = f.mod) OR (c.CPT = f.CPT AND f.mod ='xx' AND f.CPT NOT IN (SELECT CPT FROM Fees WHERE mod<>'xx'))

SQL query columns spreading

I have the following SQL query and as we see in the screenshot, there are two repeating row with the same constr_id(2015) value but with different assigned_insurance_packages.
Query:
select
ac.constr_id,
AIP.NAME as ASSIGNED_INSURANCE_PACKAGES,
ac.code,ac.constr_name,
ac.offer_name,
ac.repay_freq,
ac.min_amt,
ac.max_amt,
ac.min_downpay_percent,
ac.max_downpay_percent,
ac.downpay_amount,
ac.min_term,
(select
listagg(AF.NAME, '; ') within group(order by ACF.CONSTR_ID)
from
CREDILOGIC.ACQ_CONSTR_FEE acf, CREDILOGIC.ACQ_FEE af
where
ACF.CONSTR_ID = AC.CONSTR_ID and AF.FEE_ID = ACF.FEE_ID) as CONSTRUCTION_FEES,
INS_COMPANY.SHORT_NAME,
(select listagg(x.DURATION_MIN || '-' || TO_CHAR(x.RATE_SHIFT, '90.99') || ',' || x.DURATION_MAX || '-' || TO_CHAR(x.RATE_SHIFT, '90.99'), '; ') within group (order by X.CONSTRUCTION_ID)
from credilogic.ACQ_CONSTRUCTION_BASERATE x
where X.CONSTRUCTION_ID = AC.CONSTR_ID) as RATE
from
CREDILOGIC.ACQ_CONSTRUCTION ac
left join
CREDILOGIC.ACQ_CONSTR_INSPACKAGE aci on ACI.CONSTR_ID = AC.CONSTR_ID
and ACI.DELETED_TSTAMP is null
left join
CREDILOGIC.ACQ_INSURANCE_PACKAGE aip on AIP.INSURANCE_PACKAGE_ID = ACI.INSURANCE_PACKAGE_ID
left join
credilogic.ath_party ins_company ON INS_COMPANY.PARTY_ID = aip.PARTY_ID
left join
credilogic.ACQ_CONSTRUCTION_DUEDATE acd on ac.constr_id = acd.constr_id
left join
credilogic.ACQ_APPLICATION acp on ac.constr_id = acp.construction_id
I am just going to create two additional columns like 0.3% insurance pack and 0.5% insurance pack to put ASSIGNED_INSURANCE_PACKAGES values into different columns like in the picture below

issues combining two columns using concat

I am having issues with combining two columns into the one using mssql
table 1 format:
|| WJCPrefix || WJCNo ||
|| UK-R/SWJC/14/ || 1234 ||
|| UK-R/CUWJC/14/ || 2345 ||
|| UK-R/CUWJC/14/ || 3456 ||
|| UK-R/SWJC/14/ || 4567 ||
|| UK-R/CUWJC/14/ || 5678 ||
The desired out would be:
UK-R/CUWJC/14/3456
UK-R/CUWJC/14/5678
the sql statement i am using is:
SELECT tblWJCItem.AddedDescription, concat(tblWJC.WJCPrefix, tblWJC.WJCNo) AS OurRef
FROM tblWJC
INNER JOIN tblWJCItem ON tblWJC.WJCID = tblWJCItem.WJCID;
I've also used:
SELECT tblWJCItem.AddedDescription, tblWJC.WJCPrefix + '' + tblWJC.WJCNo AS OurRef
FROM tblWJC
INNER JOIN tblWJCItem ON tblWJC.WJCID = tblWJCItem.WJCID;
I can't seem to connect these two columns could anyone point out what I am doing wrong here?
Thanks
Your first query (Concat() function) should work if you are using SQL Server 2012 or later.
For other versions, you may need to Convert()/Cast() WJCNo to a string type
SELECT t2.AddedDescription,
t1.WJCPrefix + CONVERT(Varchar(10),t1.WJCNo) AS OurRef
FROM tblWJC t1
INNER JOIN tblWJCItem t2 ON t1.WJCID = t2.WJCID;
Your first query should be fine. But you might try:
SELECT tblWJCItem.AddedDescription, tblWJC.Prefix + cast(tblWJC.WJCNo as varchar(255)) AS OurRef
FROM tblWJC INNER JOIN
tblWJCItem
ON tblWJC.WJCID = tblWJCItem.WJCID;
You might get an error in the second version if WJCno is numeric rather than a string.
I think WJCNo is numeric or int field so Convert this field to Varchar first then concat:-
SELECT tblWJCItem.AddedDescription,
tblWJC.WJCPrefix + '' + CONVERT(Varchar(10),tblWJC.WJCNo) AS OurRef
FROM tblWJC
INNER JOIN tblWJCItem ON tblWJC.WJCID = tblWJCItem.WJCID;

Joins and condition

I need to get the activity name where deletedsw='0' and eventdtm=sysdate-12. But inorder to get the activity full name it is doing the self join I think. But I am not sure how to include these condition in those query. Can anyone please help
SELECT
(DECODE(levelLess3.activitynm, NULL, '', levelLess3.activitynm || '/') ) ||
(DECODE(levelLess2.activitynm, NULL, '', levelLess2.activitynm || '/') ) ||
(DECODE(levelLess1.activitynm, NULL, '', levelLess1.activitynm || '/') ) ||
wa.activitynm as ACTIVITYFULLNM
FROM wfaactivity wa
LEFT OUTER JOIN WFAACTIVITY levelless1 ON (wa.parentid = levelless1.wfaactivityid
AND levelless1.wfaactivityid != wa.wfaactivityid)
LEFT OUTER JOIN WFAACTIVITY levelless2 ON (levelless1.parentid = levelless2.wfaactivityid
AND levelless2.wfaactivityid != levelless1.wfaactivityid)
LEFT OUTER JOIN WFAACTIVITY levelless3 ON (levelless2.parentid = levelless3.wfaactivityid
AND levelless3.wfaactivityid != levelless2.wfaactivityid)
I want to include the condition like
where wa.wfaactivityid=wspan.wfaactivityid
and wspan.deletedsw='0'
and to_char(wspan.eventdtm, 'yyyymmdd') >= to_char(sysdate-12,'yyyymmdd')
wspan is another table from where we are taking deletedsw and eventdtm
yeah I gave like this
SELECT
(DECODE(levelLess3.activitynm, NULL, '', levelLess3.activitynm || '/') ) ||
(DECODE(levelLess2.activitynm, NULL, '', levelLess2.activitynm || '/') ) ||
(DECODE(levelLess1.activitynm, NULL, '', levelLess1.activitynm || '/') ) ||
wa.activitynm as ACTIVITYFULLNM
FROM wfaactivity wa,WFAREPACTYSPAN wspan
where
wa.wfaactivityid=wspan.wfaactivityid
and wspan.deletedsw='0'
and to_char(wspan.eventdtm, 'yyyymmdd') >= to_char(sysdate-12,'yyyymmdd')
and
LEFT OUTER JOIN WFAACTIVITY levelless1 ON (wa.parentid = levelless1.wfaactivityid
AND levelless1.wfaactivityid != wa.wfaactivityid)
LEFT OUTER JOIN WFAACTIVITY levelless2 ON (levelless1.parentid = levelless2.wfaactivityid
AND levelless2.wfaactivityid != levelless1.wfaactivityid)
LEFT OUTER JOIN WFAACTIVITY levelless3 ON (levelless2.parentid = levelless3.wfaactivityid
AND levelless3.wfaactivityid != levelless2.wfaactivityid)
But I am getting the error ORA-00920 Invalid relational operator
Your select is failing because you are putting the join conditions into the where clause. Try this instead:
Select (DECODE(levelLess3.activitynm, Null, '', levelLess3.activitynm || '/') ) ||
(DECODE(levelLess2.activitynm, Null, '', levelLess2.activitynm || '/') ) ||
(DECODE(levelLess1.activitynm, Null, '', levelLess1.activitynm || '/') ) ||
wa.activitynm As ACTIVITYFULLNM
From wfaactivity wa
Join WFAREPACTYSPAN wspan On wa.wfaactivityid=wspan.wfaactivityid
Left Outer Join WFAACTIVITY levelless1 On (wa.parentid = levelless1.wfaactivityid
And levelless1.wfaactivityid != wa.wfaactivityid)
Left Outer Join WFAACTIVITY levelless2 On (levelless1.parentid = levelless2.wfaactivityid
And levelless2.wfaactivityid != levelless1.wfaactivityid)
Left Outer Join WFAACTIVITY levelless3 On (levelless2.parentid = levelless3.wfaactivityid
And levelless3.wfaactivityid != levelless2.wfaactivityid)
Where wspan.deletedsw='0'
And TO_CHAR(wspan.eventdtm, 'yyyymmdd') >= TO_CHAR(SYSDATE-12,'yyyymmdd')
EDIT
You can join any tables you want in the way you need, but you have to be sure on how you are joining them. From your question and comment it seems (sorry if it is not the case) you are not very familiar with SQL joins.
If that is so I suggest you read this excellent explanation on SQL joins. Depending on how you join the tables you might not get the data you want.
HTH
It looks like you're trying to build a hierarchy - why not use a hierarchical query instead?
select reverse (sys_connect_by_path (reverse (wf.activitynm), '/') as activityfullnm
from wfaactivity wf
inner join wfarepactyspan wspan
on wa.wfaactivityid = wspan.wfaactivityid
start with ( wspan.deletedsw = 0 and
and wspan.eventdtm >= sysdate - 12)
connect by nocycle prior wf.wfactivityid = wf.parentid
where level <= 4