Hope you all well.
I am able execute the below code and got the right output in oracle.But when trying to create a view its giving the error - a column may not be joined to sub query.
The view is getting created in sql server on the same query but in oracle its giving an error.please help.
select c.Contractid
FROM FCT_EIT_CONTRACT c LEFT OUTER JOIN
DIM_EIT_PROCESS_INSTANCE psi ON psi.SURR_ID = c.PROCESS_INSTANCE_SKEY
LEFT OUTER JOIN
DIM_EIT_ACTION wa ON psi.ACTION_SKEY wa.SURR_ID
LEFT OUTER JOIN
DIM_EIT_ACTION_HISTORY ah ON wa.SURR_ID = ah.ACTION_SKEY
AND psi.SURR_ID = ah.PROCESS_INSTANCE_SKEY
AND ah.ACTION_HISTORY_ID =(SELECT MAX(ACTION_HISTORY_ID) AS Expr1
FROM DIM_EIT_ACTION_HISTORY a
WHERE (PROCESS_INSTANCE_SKEY = c.PROCESS_INSTANCE_SKEY)
AND
(psi.ACTION_SKEY = ACTION_SKEY)))
LEFT OUTER JOIN
DIM_EIT_STEP ws ON ws.SURR_ID = wa.NEXT_STEP_SKEY
WHERE (psi.CurrentStepId NOT IN (100, 130, 131, 132, 900, 902, 910))
Would it help if you moved the offending part of the query to the WHERE clause, e.g.
SELECT c.contractid
FROM fct_eit_contract c
LEFT OUTER JOIN dim_eit_process_instance psi ON psi.surr_id = c.process_instance_skey
LEFT OUTER JOIN dim_eit_action wa ON psi.action_skey wa.surr_id
LEFT OUTER JOIN dim_eit_action_history ah ON wa.surr_id = ah.action_skey
AND psi.surr_id = ah.process_instance_skey
LEFT OUTER JOIN dim_eit_step ws ON ws.surr_id = wa.next_step_skey
WHERE psi.currentstepid NOT IN (100, 130, 131, 132, 900, 902, 910)
-- subquery moved down here
AND ah.action_history_id = (SELECT MAX(action_history_id) AS expr1
FROM dim_eit_action_history a
WHERE process_instance_skey = c.process_instance_skey
AND psi.action_skey = action_skey
);
select
c.contractid
FROM FCT_EIT_CONTRACT c , DIM_EIT_PROCESS_INSTANCE psi, DIM_EIT_ACTION wa, DIM_EIT_ACTION_HISTORY ah,
(select MAX(ACTION_HISTORY_ID) AS ACTION_HISTORY_ID, ACTION_SKEY, PROCESS_INSTANCE_SKEY from DIM_EIT_ACTION_HISTORY group by ACTION_SKEY, PROCESS_INSTANCE_SKEY) a ,
DIM_EIT_STEP ws
where psi.SURR_ID(+) = c.PROCESS_INSTANCE_SKEY
and psi.ACTION_SKEY = wa.SURR_ID(+)
and wa.SURR_ID = ah.ACTION_SKEY(+)
AND psi.SURR_ID = ah.PROCESS_INSTANCE_SKEY(+)
AND ah.ACTION_HISTORY_ID = a.ACTION_HISTORY_ID(+)
and ((a.ACTION_HISTORY_ID is not null and ah.ACTION_HISTORY_ID is not null and ah.PROCESS_INSTANCE_SKEY is not null) or
(a.ACTION_HISTORY_ID is null and ah.ACTION_HISTORY_ID is null and ah.PROCESS_INSTANCE_SKEY is null))
-- and
-- and c.PROCESS_INSTANCE_SKEY = a.PROCESS_INSTANCE_SKEY(+)
-- and psi.ACTION_SKEY = a.ACTION_SKEY
and ws.SURR_ID`+) = wa.NEXT_STEP_SKEY
and (psi.CurrentStepId NOT IN (100, 130, 131, 132, 900, 902, 910)) and contractid in (1313,27, 221)
Related
I've got a problem with the syntax of a SQL query. It works sometimes and sometimes not. It's defenitly a problem with the query.
An error at or near "INTERSECTSELECT".
SQL Error: 0, SQLState: 42601
SELECT DISTINCT s.id,
s.title,
s.question,
s.comments,
s.start_date,
s.end_date,
s.motivation,
s.goals,
s.method,
s.type,
s.channel,
s.rhythm,
s.sample
FROM study s
LEFT OUTER JOIN study_customer_information sci
ON sci.study_id = s.id
LEFT OUTER JOIN customer_information ci
ON ci.id = sci.customer_information_id
WHERE s.is_active = :isActive
AND
s.language = :language AND s.id IN (SELECT sci.study_id
FROM study_customer_information sci
INNER JOIN customer_information ci
ON ci.id = sci.customer_information_id
WHERE ci.name_de in (:customer_informations)
GROUP BY sci.study_id
HAVING COUNT(sci.study_id) = :number_customer_informations INTERSECT SELECT st.study_id
FROM study_touchpoint st
INNER JOIN touchpoint tp ON tp.id = st.touchpoint_id
INNER JOIN subject_area sa ON sa.id = tp.subject_area_id
WHERE sa.name_DE = :subject_areas_0 INTERSECT SELECT st.study_id
FROM study_touchpoint st
INNER JOIN touchpoint tp ON tp.id = st.touchpoint_id
INNER JOIN touch_point_type tpt ON tpt.id = tp.touch_point_type_id
WHERE tpt.name_DE = :touchpoint_types_0 INTERSECT SELECT sth.study_id
FROM study_theme sth
INNER JOIN theme th
ON th.id = sth.theme_id
WHERE th.name_de in (:themes)
GROUP BY sth.study_id
HAVING COUNT(sth.study_id) = :number_themes) ORDER BY s.title
**The below query is working badly, and I'm planning to replace case stmt in where clause with temp table. Pls suggest to me some option to rewrite this query
Is there a way to simplify this into multiple SQLs
Also explain me how this case stmt works in where clause**
select DISTINCT
ph.order_type_cd,
c.order_num,
ph.created_date,
os.order_status_desc,
ph.facility_name,
PH.vendor_order_num,
l.lic_nm,
(u.last_nm + ', ' + u.first_nm )as requestor_nm,
bl.billing_location_desc,
ph.ship_to_name,
dm.dispatch_method_name_desc as courier,
PH.po_last_updated_dt as last_updated_date,
(u1.last_nm + ', ' + u1.first_nm )as last_updated_by,
ph.right_grp_id,
c.line_id,
a.material_product_id,
a.parent_material_product_id
from avt_po_detail c
inner join avt_po_hdr ph on ph.order_num = c.order_num
left outer join avt_material_product AS a on a.material_product_id=c.material_product_id
INNER JOIN #entity_ids po on po.entity_id = c.order_num --or #select_pos = 0 )
LEFT OUTER JOIN dbo.ert_product AS pc ON pc.product_id = a.product_id
left outer join ert_product_type as pt on pt.product_type_cd = pc.product_type_cd
LEFT OUTER JOIN dbo.ert_product_xref as xref on xref.product_id = a.parent_product_id AND xref.version_id = 1
left outer join avt_order_status AS OS ON OS.order_status_cd = PH.order_status_cd
left outer join avt_licensee l on l.lic_id = ph.lic_id
left outer join avt_po_from pf on pf.material_product_id = a.material_product_id and pf.line_id = c.line_id
left outer join avt_po_audio_detail pad on pad.line_id = c.line_id
left outer join avt_materials_trans_material MTM on mtm.sequence_no = c.video_seq_no
left outer join avt_user u on u.userid = ph.requestor_id
left outer join avt_user u1 on u1.userid = ph.po_last_updated_by
left outer join avt_billing_location bl on bl.billing_location_cd = PH.billing_location_cd
left outer join avt_dispatch_method_name dm on dm.dispatch_method_name_id = PH.dispatch_method_name_id
left outer join avt_right_group arg on arg.right_grp_id = ph.right_grp_id
left outer join #prod product on product.product_id=a.product_id and (product.version_id=c.dist_version_id OR product.version_id = 1)
where (pf.from_desc in ( select from_desc from #from_desc ) or #select_form = 0)
and (case WHEN c.dist_version_id IS NULL THEN c.UCS_prod_no
ELSE
CASE
WHEN isnull(pt.version_control_ind, 'N') = 'Y' THEN xref.rss_prod_no
WHEN
isnull(pt.version_control_ind, 'N') = 'N' AND
xref.rss_prod_no IS NULL AND
xref.rss_film_id IS NULL THEN xref.rss_titleid
WHEN
isnull(pt.version_control_ind, 'N') = 'N' AND
xref.rss_prod_no IS NOT NULL AND
xref.rss_film_id IS NULL THEN substring(pc.glacct, 24, 5) -- ASR 3290687
WHEN isnull(pt.version_control_ind, 'N') = 'N' AND xref.rss_film_id IS NOT NULL THEN isnull(substring(pc.glacct, 24, 5), -- ASR 3290687
(
SELECT substring(dbo.ert_product.glacct, 24, 5) -- ASR 3290687
FROM dbo.ert_product
WHERE dbo.ert_product.product_id = a.parent_product_id
))
END
END in (select prod_no from #prod_no) or #prod_no = 0)
I have a crystal report using the SQL command below.
I am wondering if anyone can assist me with the reason why I am getting duplicate people appearing in my report.
At the moment I get multiple lines for a sales account manager (SAM),
I want one line per SAM.
My 1st Group Header is based on the Sector Code,
2nd group header is on command.sector,
3rd group header is on SAM
SELECT DISTINCT
'Actuals' as [Trans Type],
ER101_ACCT_ORDER_DTL.ER101_START_DATE_ISO as [Order Date],
ER101_ACCT_ORDER_DTL.ER101_ENT_DATE_ISO as [Ent Date],
year(dateadd(month,6,ER101_ACCT_ORDER_DTL.ER101_START_DATE_ISO)) as [FYR],
MONTH(DATEADD(M, 6, ER101_ACCT_ORDER_DTL.ER101_START_DATE_ISO)) as [FYP],
DATEADD(mm, DATEDIFF(mm, 0, ER101_ACCT_ORDER_DTL.ER101_START_DATE_ISO), 0) as [PStart],
DATEADD (dd, -1, DATEADD(mm, DATEDIFF(mm, 0, ER101_ACCT_ORDER_DTL.ER101_START_DATE_ISO) + 1, 0)) as [Pend],
Revenue =
Case
When ER101_ACCT_ORDER_DTL.ER101_PHASE = '1' and ER101_ACCT_ORDER_DTL.ER101_COMPL_STS = 'N'
then ER101_ACCT_ORDER_DTL.ER101_EXT_CHRG
When ER101_ACCT_ORDER_DTL.ER101_PHASE = '5' and ER101_ACCT_ORDER_DTL.ER101_COMPL_STS = 'N'
then ER101_ACCT_ORDER_DTL.ER101_EXT_CHRG
Else 0
End,
isnull(MM405_USER_NAME,'No SAM') AS [SAM],
ER101_ACCT_ORDER_DTL.ER101_DESC as [Desc],
EV200_EVENT_MASTER.EV200_EVT_ID as [EventID],
isnull(SALESACCT.EV870_TYPE,'NoSec') as [Sector],
isnull(CCRPF_ACCT_TYPE_DESC,'ZZ - No Sector') as [Sector Name],
EV130_STATUS_MASTER.EV130_STATUS_DESC as [Event Status Desc],
isnull(EV800_USER_FLD_6X,'N') as [Budgeted]
FROM ER101_ACCT_ORDER_DTL WITH (NOLOCK)
LEFT OUTER JOIN EV700_FUNC_MASTER WITH (NOLOCK)
ON ER101_ACCT_ORDER_DTL.ER101_ORG_CODE = EV700_FUNC_MASTER.EV700_ORG_CODE
AND ER101_ACCT_ORDER_DTL.ER101_EVT_ID = EV700_FUNC_MASTER.EV700_EVT_ID
AND ER101_ACCT_ORDER_DTL.ER101_FUNC_ID = EV700_FUNC_MASTER.EV700_FUNC_ID
LEFT OUTER JOIN EV800_SPACE_MASTER WITH (NOLOCK)
ON EV700_FUNC_MASTER.EV700_SPACE = EV800_SPACE_MASTER.EV800_SPACE_CODE
AND EV700_FUNC_MASTER.EV700_ORG_CODE = EV800_SPACE_MASTER.EV800_ORG_CODE
LEFT OUTER JOIN EV200_EVENT_MASTER WITH (NOLOCK)
ON ER101_ACCT_ORDER_DTL.ER101_ORG_CODE = EV200_EVENT_MASTER.EV200_ORG_CODE
AND ER101_ACCT_ORDER_DTL.ER101_EVT_ID = EV200_EVENT_MASTER.EV200_EVT_ID
LEFT OUTER JOIN EV870_ACCT_MASTER WITH (NOLOCK)
ON EV200_EVENT_MASTER.EV200_ORG_CODE = EV870_ACCT_MASTER.EV870_ORG_CODE
AND EV200_EVENT_MASTER.EV200_SLSPER = EV870_ACCT_MASTER.EV870_ACCT_CODE
LEFT OUTER JOIN EV870_ACCT_MASTER SALESACCT WITH (NOLOCK)
ON EV200_EVENT_MASTER.EV200_ORG_CODE = SALESACCT.EV870_ORG_CODE
AND EV200_EVENT_MASTER.EV200_CUST_NBR = SALESACCT.EV870_ACCT_CODE
LEFT OUTER JOIN CCRPF_ACCT_TYPES WITH (NOLOCK)
ON SALESACCT.EV870_TYPE = CCRPF_ACCT_TYPE
LEFT OUTER JOIN MM405_USER_MASTER_EXT WITH (NOLOCK)
ON EV870_ACCT_MASTER.EV870_USERID = MM405_USER_MASTER_EXT.MM405_USER_ID
LEFT OUTER JOIN EV130_STATUS_MASTER WITH (NOLOCK)
ON EV200_EVENT_MASTER.EV200_EVT_STATUS = EV130_STATUS_MASTER.EV130_STATUS_CODE
LEFT OUTER JOIN EV370_RES_MASTER WITH (NOLOCK)
ON ER101_ACCT_ORDER_DTL.ER101_ORG_CODE = EV370_RES_MASTER.EV370_ORG_CODE
AND ER101_ACCT_ORDER_DTL.ER101_NEW_RES_TYPE = EV370_RES_MASTER.EV370_NEW_RES_TYPE
AND ER101_ACCT_ORDER_DTL.ER101_RES_CODE = EV370_RES_MASTER.EV370_RES_CODE
WHERE EV200_ORG_CODE = '10' and EV200_EVT_STATUS in ('33', '34', '36', '49','50', '52') and NOT(EV200_EVT_TYPE IN ('MOS','MP','GB'))
and ER101_RES_CLASS <> '8' and ER101_ORD_TYPE = 'SO'
and not(EV370_RES_MASTER.EV370_MAJOR_GROUP in ('SRVCHR', 'EBOND', 'SCHARG','GIFTC'))
UNION
Select 'Targets' as [Trans Type],
MM012_PERIOD_STDATE as [Order Date],
GL010_ENT_STAMP as [Ent Date],
MM012_FISCAL_YR as [FYR],
MM012_FISCAL_PERIOD as [FYP],
MM012_PERIOD_STDATE as [PStart],
MM012_PERIOD_ENDATE as [Pend],
GL010_BUD_PTD as [Revenue],
'Budget SAM' as [SAM],
GL010_ACCOUNT as [Desc],
null as [Event ID],
GL001_SHORT_DESC as [Sector],
[Sector Name] =
Case
When CCRPF_ACCT_TYPE_DESC is null then 'OLD - ' + GL001_DESC
Else CCRPF_ACCT_TYPE_DESC
End,
'Budget Event Status Desc' as [Event Status Desc],
'Targets' as [Budgeted]
FROM GL010_BALANCES WITH (NOLOCK)
LEFT OUTER JOIN GL001_ACCOUNT_MASTER
WITH (NOLOCK) ON GL010_ORG_CODE = GL001_ORG_CODE
AND GL010_ACCOUNT = GL001_ACCOUNT
LEFT OUTER JOIN MM012_FISCAL_PERIODS
WITH (NOLOCK) ON GL010_ORG_CODE = MM012_ORG_CODE
AND GL010_FISCAL_YR = MM012_FISCAL_YR
AND GL010_FISCAL_PERIOD = MM012_FISCAL_PERIOD
LEFT OUTER JOIN dbo.CCRPF_ACCT_TYPES
WITH (NOLOCK) ON GL001_SHORT_DESC = CCRPF_ACCT_TYPE
Where GL001_ACCT_TYPE = 'SS' and LEFT(GL001_ACCOUNT_MASTER.GL001_ACCOUNT,3)='SEC'
Msg 156, Level 15, State 1, Line 8
Incorrect syntax near the keyword 'CASE'
I am trying to join columns based on the column value.
If case conditon 1 is true then i want to join
ON im.ItemNumber = left(tr.itemnumber,len(tr.itemnumber)-4)
if Case condition 2 is true then
ON tr.ItemNumber = im.LegacyItemNumber
else
tr.ItemNumber = im.ItemNumber
SELECT
im.Category as RootCategory,GETDATE() AS LoadDate,tr.*
into transactionreport_stage_testNN
FROM transaction tr
LEFT OUTER JOIN ALLDW_ora.dbo.Location(NOLOCK) loc ON tr.location=loc.location
CASE
when
right(tr.itemnumber,4) = '_old' then
LEFT OUTER JOIN [Inventory](NOLOCK) im
ON im.ItemNumber = left(tr.itemnumber,len(tr.itemnumber)-4)
when
tr.itemnumber <> im.ItemNumber
then
LEFT OUTER JOIN [Inventory](NOLOCK) im
ON tr.ItemNumber = im.LegacyItemNumber
else
LEFT OUTER JOIN [Inventory](NOLOCK) im
ON tr.ItemNumber = im.itemnumber
end
AND im.Location=loc.LocationNo
Schema
You should probably just use AND's and OR's
LEFT OUTER JOIN [Inventory](NOLOCK) im ON im.Location=loc.LocationNo
AND (
(right(tr.itemnumber,4) = '_old' AND im.ItemNumber = left(tr.itemnumber,len(tr.itemnumber)-4))
OR
(tr.itemnumber <> im.ItemNumber AND tr.ItemNumber = im.LegacyItemNumber)
OR
(tr.ItemNumber = im.itemnumber)
)
it may just be as simple as
SELECT im.Category AS RootCategory,
GETDATE() AS LoadDate,
tr.*
INTO #transactionreport_stage_testNN
FROM [transaction] tr
LEFT OUTER JOIN ALLDW_ora.dbo.Location (NOLOCK) loc ON tr.location = loc.location
LEFT OUTER JOIN [Inventory] (NOLOCK) im ON im.Location = loc.LocationNo
AND REPLACE(tr.itemnumber, '_old', '') IN (im.itemnumber, im.legacyitemnumber)
I receive an error
Coversion of varchar to float
when I write
set rowcount = 1
on first line of my code.
My script is:
select
vh.VchNum, ct.Val, r.RoutSheetNo, vi.FinalQty,
rh.RequestNo, vh.VchDate,
p.PartCode, d.Title, co.val
from
inv.InvVchHdr vh
join
acc.DL d on d.AccNum = vh.DLREF
join
inv.InvVchItm vi on vi.VchHdrRef = vh.VchHdrID
join
inv.InvVchItmCtrl ct on ct.VchItmRef = vi.VchItmID
join
QCS.QcsCertificateOfAnalysis q on q.Number = ct.Val
join
USR.kalaf_info_p kp on kp.Id = q.QcsCertificateOfAnalysisId
join
USR.coil_trace co on co.id = kp.coil_id
join
inv.Part p on p.Serial = vi.PartRef
join
inv.InvRqstItm rq on rq.RqstItmID = vi.RefNum
join
inv.InvRqstHdr rh on rh.RqstHdrID = rq.HdrRef
join
PRD.vwPrdOrderItemPlan pl on rh.OrdPlnBase = pl.OrdPlnId
join
prd.prdroutsheet r on r.OrdPlnRef = pl.OrdPlnId
where
pl.pPartRef not in (select pipe_code from usr.pipe_kalaf)
and pl.pPartRef not in (select Serial from inv.Part where PartName like '%لاف%')
and vi.VchType = 57
union
select vh.VchNum,ct.Val,pl.OrdPlnNo
,vi.FinalQty,
rh.RequestNo,vh.VchDate,
p.PartCode,d.Title,co.val from
inv.InvVchHdr vh
join acc.DL d
on d.AccNum=vh.DLREF
join
inv.InvVchItm vi
on vi.VchHdrRef=vh.VchHdrID
join inv.InvVchItmCtrl ct
on ct.VchItmRef=vi.VchItmID
join QCS.QcsCertificateOfAnalysis q
on q.Number=ct.Val
join USR.kalaf_info_p kp
on kp.Id=q.QcsCertificateOfAnalysisId
join USR.coil_trace co
on co.id=kp.coil_id
join
inv.Part p
on p.Serial=vi.PartRef
join inv.InvRqstItm rq
on rq.RqstItmID=vi.RefNum
join inv.InvRqstHdr rh
on rh.RqstHdrID=rq.HdrRef
join PRD.vwPrdOrderItemPlan pl
on rh.OrdPlnBase=pl.OrdPlnId
where pl.pPartRef in (select pipe_code from usr.pipe_kalaf) and vi.VchType=57
SET ROWCOUNT 0
i use sql server 2000 and when I remove setrowcount statement, problem resolve.
please help me
Remove the =(equal) sign
from
set rowcount = 1
To
SET ROWCOUNT 1