DaxStudio - Implementing data lineage with table variables - dax

I have 2 problems :
When running the code below with DaxStudio, I get an error along the lines of "TREATAS function expects a complete column reference" ;
How can I implement data lineage with table variables not coming from a table of a data model?
Is there a simple way of adding to tbl_ITEMS_REFS the consolidated sum of tbl_SALES[AMOUNT]?
The code :
EVALUATE
VAR tbl_SALES =
DATATABLE(
"SALES_NBR" , INTEGER
, "ITEM_CODE" , STRING
, "AMOUNT" , INTEGER
, {
{ 1 , "X" , 10 }
, { 2 , "Y" , 10 }
, { 3 , "Z" , 10 }
, { 4 , "X" , 20 }
, { 5 , "Z" , 20 }
, { 6 , "Z" , 10 }
, { 7 , "Z" , 20 }
, { 8 , "X" , 30 }
, { 9 , "X" , 30 }
, { 10 , "Y" , 30 }
}
)
VAR tbl_ITEMS_REFS =
DATATABLE(
"Origin" , STRING
, "Code" , STRING
, {
{" Department 1 " , "X"}
, {" Department 1 " , "Y"}
, {" Department 2 " , "Z"}
}
)
VAR tbl_ITEMS_DATA_LINEAGE =
TREATAS (
SELECTCOLUMNS ( tbl_ITEMS_REFS , [Code] )
, SELECTCOLUMNS ( tbl_SALES , [ITEM_CODE] )
)
RETURN
ADDCOLUMNS (
tbl_ITEMS_DATA_LINEAGE
, "Total_Sales"
, CALCULATE (
SUM ( [AMOUNT] )
)
)
Thank you for your help.
Addendum
For question 2, by "adding to tbl_ITEMS_REFS", I was thinking of a simple way to get something like this :
Department 1 X 90
Department 1 Y 40
Department 2 Z 60

TREATAS won't work with virtual tables. If you add tbl_SALES to an actual data model so it is a real physical table and connect DAX Studio to it, the code works fine as long as you change the following:
EVALUATE
VAR tbl_ITEMS_REFS =
DATATABLE(
"Origin" , STRING
, "Code" , STRING
, {
{" Department 1 " , "X"}
, {" Department 1 " , "Y"}
, {" Department 2 " , "Z"}
}
)
VAR tbl_ITEMS_DATA_LINEAGE =
TREATAS (
SELECTCOLUMNS ( tbl_ITEMS_REFS , [Code] )
, tbl_SALES[ITEM_CODE]
)
RETURN
ADDCOLUMNS (
tbl_ITEMS_DATA_LINEAGE
, "Total_Sales"
, CALCULATE (
SUM ( tbl_SALES[AMOUNT] )
)
)

Related

How to perform a column calculation in a CALCULATE()

My table looks like this:
Doc Code
A 61
A 61X
B 62
B 61
C 61
C 62
C 62X
I am trying to create a column in DAX that just checks whether a Code contains an X by Doc. So the result should look like this:
Doc Code DAXColumn
A 61 TRUE
A 61X TRUE
B 62 FALSE
B 61 FALSE
C 61 TRUE
C 62 TRUE
C 62X TRUE
I want to do this:
DAXColumn =
VAR currentDoc = Doc
RETURN
CALCULATE(IF(ISERROR(SEARCH("X",Doc)) = TRUE, FALSE, TRUE),
FILTER(myTable,Doc = currentDoc))
It looks like I can't pass a column into the CALCULATE parameter. How could I get the results I am looking for? Thanks in advance.
Column =
VAR _1 =
SUMMARIZE (
FILTER ( _fact, CONTAINSSTRING ( _fact[Code], "X" ) ),
[Doc],
[Code]
)
VAR _2 =
CALCULATE ( MAXX ( FILTER ( _1, [Doc] = MAX ( _fact[Doc] ) ), [Code] ) )
VAR _3 =
SWITCH ( TRUE (), ISBLANK ( _2 ) = TRUE (), FALSE (), TRUE () )
RETURN
_3
Here is my suggestion - I find this code a bit more readable so it's easier to understand at a glance what is going on.
Contains X :=
VAR _codes =
CALCULATETABLE (
VALUES ( 'Table'[Code] ),
ALLEXCEPT ( 'Table' , 'Table'[Doc] )
)
VAR _filter =
FILTER (
_codes ,
CONTAINSSTRING ( [Code] , "X" )
)
VAR _count = COUNTROWS ( _filter )
RETURN IF ( _count > 0 , TRUE , FALSE )
The logic:
Calculate a single column table with all values of Code for the current (row context) value of Doc
Apply a filter over the codes table looking for the desired string
Count the rows in the remaining table
If the count is zero, the _count variable will evaluate to blank. For a non-zero count we want to return TRUE.

Ways to optimize DB2 Query

I have used the below SQL statement to create a DB2 view. Can someone help me on how to improve this view performance as it runs slow sometimes.
The one thing I noted is that it runs slow the first time but then for subsequent runs, it picks up speed. I have analyzed with the visual explain but when it runs slow, I don't see any index advises. So not really sure how to optimize this.
-- Generate SQL
-- Version: V7R4M0 190621
-- Generated on: 02/09/21 03:08:31
-- Relational Database: BIGBLUE
-- Standards Option: Db2 for i
CREATE VIEW IESQAFILE.PSCMPORDVW
AS
WITH INPROGRESS AS
(
SELECT
DIODR#
, DIDISP
, DIUNIT
, DISTST
, DIAPRV
, DIETAD
, DITRLR AS TRAILER_ID
, DIDR1
, DIETAT
FROM
IESQAFILE.LOAD
WHERE
DIETAD <> 0
AND DIETAT <> '0000'
ORDER BY
1
)
, STOPGROUP AS
(
SELECT
SOORD STOPORDER
, COUNT(*) STOPSREMAIN
, MIN(SOSTP#) NEXTSTOP
, MAX(SOAPPR) APPTREQ
FROM
PAVT.STOP
INNER JOIN
INPROGRESS
ON
DIODR# = SOORD
WHERE
SOARDT = 0
GROUP BY
SOORD
ORDER BY
1
)
, STOPAPPTS AS
(
SELECT
SOORD APPTORDER
, SOCUST STOPCUST
, SOEDA ETADATE
, SOETA ETATIME
, SOADT1 EARLYDATE
, SOATM1 EARLYTIME
, SOADT2 LATEDATE
, SOATM2 LATETIME
, SOCTYC NEXTCITY
, SOSTP# APPTSTOP
, SOST NEXTSTATE
FROM
IESQAFILE.STOPOFF
INNER JOIN
STOPGROUP
ON
STOPORDER = SOORD
AND NEXTSTOP = SOSTP#
)
SELECT
ORDER_NUMBER
, SHIPPER_ID
, SHIPPER_NAME
, SHIPPER_ADDRESS_1
, SHIPPER_ADDRESS_2
, SHIPPER_CITY
, SHIPPER_ST
, SHIPPER_ZIP
, SHIPPER_ZIP_EXT
, LOAD_AT_ID
, LOAD_AT_NAME
, LOAD_AT_ADDRESS_1
, LOAD_AT_ADDRESS_2
, LOAD_AT_CITY
, LOAD_AT_ST
, LOAD_AT_ZIP
, LOAD_AT_ZIP_EXT
, LOAD_AT_LATITUDE
, LOAD_AT_LONGITUDE
, EARLY_PU_DATE_TIME
, LATE_PU_DATE_TIME
, EARLY_DELV_DATE_TIME
, EST_REVENUE
, ORDER_DIV
, CONSIGNEE_ID
, CONSIGNEE_NAME
, CONSIGNEE_ADDRESS_1
, CONSIGNEE_ADDRESS_2
, CONSIGNEE_CITY
, CONSIGNEE_ST
, CONSIGNEE_ZIP
, CONSIGNEE_ZIP_EXT
, CONSIGNEE_LATITUDE
, CONSIGNEE_LONGITUDE
, TRAILER_TYPE
, ORDER_MESSAGE
, ADDITIONAL_STOPS
, CMDTY_CODE
, CMDTY_DESCRIPTION
, ORDER_MILES
, ORDER_WGT
, ORIGIN_CITY_CODE
, ORIGIN_CITY
, ORIGIN_ST
, DEST_CITY_CODE
, DEST_CITY_NAME
, DEST_ST
, PICK_UP_AREA
, PLAN_INFO
, NUMBER_LDS
, NUMBER_DISP
, SHIP_DATE_TIME
, NEW_PICKUP_AREA
, EQUIPMENT_NUMBER
, APPT_REQ
, APPT_MADE
, PRE_T_SEQ
, PRE_T_AREA
, LOAD_DISPATCHED
, CUST_SERV_REP
, NEGOTIATIONS
,
(
CASE
WHEN UNUNIT IS NOT NULL
THEN UNUNIT
ELSE ' '
END
)
UNIT_DISPATCHED
,
(
CASE
WHEN UNSUPR IS NOT NULL
THEN UNSUPR
ELSE ' '
END
)
DRIVER_MGR_CODE
, COALESCE(SUPNAM, ' ') DRIVER_MGR_NAME
,
(
CASE
WHEN UNFMGR IS NOT NULL
THEN UNFMGR
ELSE ' '
END
)
FLEET_MGR_CODE
, COALESCE(FLTNAM,' ') FLEET_MGR_NAME
,
(
CASE
WHEN UNTRL1 IS NOT NULL
THEN UNTRL1
ELSE ' '
END
)
TRAILER_ID,
DIDISP DISPATCH_NUMBER,
(COALESCE(BCMCNEW, ' ')) FED_MC_ID,
DIUNIT DISPATCHED_UNIT,
CASE
WHEN UNETAD <> 0
AND UNETAT = ''
THEN SMIS.CVTDATETIM(CHAR(UNETAD),'0000', (
SELECT
SUBSTR(DATA_AREA_VALUE, 1109, 2) AS TIMEZONE
FROM
TABLE(QSYS2.DATA_AREA_INFO('COMPAN', '*LIBL'))
)
)
WHEN UNETAD <> 0
THEN SMIS.CVTDATETIM(CHAR(UNETAD),UNETAT, (
SELECT
SUBSTR(DATA_AREA_VALUE, 1109, 2) AS TIMEZONE
FROM
TABLE(QSYS2.DATA_AREA_INFO('COMPAN', '*LIBL'))
)
)
WHEN UNETAD = 0
THEN '0000-00-00T00:00:00-00:00'
END AS ETA_DATE_TIME,
NEXTSTOP , CASE
WHEN SOARDT <> 0
AND SOARTM = ''
THEN SMIS.CVTDATETIM(CHAR(SOARDT),'0000', (
SELECT
SUBSTR(DATA_AREA_VALUE, 1109, 2) AS TIMEZONE
FROM
TABLE(QSYS2.DATA_AREA_INFO('COMPAN', '*LIBL'))
)
)
WHEN SOARDT <> 0
THEN SMIS.CVTDATETIM(CHAR(SOARDT),SOARTM, (
SELECT
SUBSTR(DATA_AREA_VALUE, 1109, 2) AS TIMEZONE
FROM
TABLE(QSYS2.DATA_AREA_INFO('COMPAN', '*LIBL'))
)
)
WHEN SOARDT = 0
THEN '0000-00-00T00:00:00-00:00'
END AS STOP_ARRIVAL_DATE_TIME
, CASE
WHEN SOLUDT <> 0
AND SOLUTM = ''
THEN SMIS.CVTDATETIM(CHAR(SOLUDT),'0000', (
SELECT
SUBSTR(DATA_AREA_VALUE, 1109, 2) AS TIMEZONE
FROM
TABLE(QSYS2.DATA_AREA_INFO('COMPAN', '*LIBL'))
)
)
WHEN SOLUDT <> 0
THEN SMIS.CVTDATETIM(CHAR(SOLUDT),SOLUTM, (
SELECT
SUBSTR(DATA_AREA_VALUE, 1109, 2) AS TIMEZONE
FROM
TABLE(QSYS2.DATA_AREA_INFO('COMPAN', '*LIBL'))
)
)
WHEN SOLUDT = 0
THEN '0000-00-00T00:00:00-00:00'
END AS STOP_DEPART_DATE_TIME
, ORBAMT ORDER_INV_AMT
, ORARST AR_STATUS_FLAG
, DISTST SETTLEMENT_FLAG
, DIAPRV APPROVED_FOR_PAY
, BCCARR CARRIER_CODE
, BCNAME CARRIER_NAME
, BCADDR CARRIER_ADDRESS_1
, BCADR2 CARRIER_ADDRESS_2
, BCCITY CARRIER_CITY
, BCST CARRIER_ST
, BCZIP CARRIER_ZIP
FROM
INPROGRESS
INNER JOIN
IESQAFILE.PSMAINORVW A
ON
DIODR# = ORDER_NUMBER
AND DIDISP = NUMBER_DISP
AND
(
SUBSTR(ORDER_NUMBER, 1, 2) <> 'DH'
AND SUBSTR(ORDER_NUMBER, 1, 1) <> 'M'
)
LEFT OUTER JOIN
IESQAFILE.STOPOFF
ON
DIODR# = SOORD
AND SOSTP# = 90
LEFT OUTER JOIN
IESQAFILE.LMCARR
ON
DIUNIT = BCCARR
LEFT OUTER JOIN
IESQAFILE.MMILES
ON
MMORD# = DIODR#
AND MMRECTYPE = 'D'
AND MMDSP# = DIDISP
EXCEPTION JOIN
IESQAFILE.ORDBILL B
ON
B.ORODR# = DIODR#
AND B.ORSEQ = ' '
AND ORARST = '1'
LEFT OUTER JOIN
STOPGROUP
ON
STOPORDER = DIODR#
LEFT OUTER JOIN
STOPAPPTS
ON
APPTORDER = STOPORDER
AND APPTSTOP = NEXTSTOP
LEFT OUTER JOIN
IESQAFILE.UNITS
ON
UNUNIT = DIUNIT
AND UNORD# = ORDER_NUMBER
LEFT OUTER JOIN
IESQAFILE.SUPMAST
ON
SUPCDE = UNSUPR
LEFT OUTER JOIN
IESQAFILE.FLTMAST
ON
UNFMGR = FLTCDE
WHERE
DIETAD <> 0
AND DIETAT <> '0000'
RCDFMT PSCMPORDVW ;
Without seeing the Visual Explain (VE) data (and it's not really something easily sharable here) giving you a "magic wand" answer not likely.
I'm surprised you don't see any indexes advised. But even so, you should be able to compare the VE data between "fast" and "slow" runs to see where the differences are. Make sure you have "View"-->"Highlighting"-->"Expensive Icons"-->... turned on. Also check "Options"-->"Attribute Detail" and "Options"-->"Graph Detail"...
Always a good idea to be using the latest and greatest version (1.1.8.6) of Access Client Solutions (ACS) which includes the Run SQL Script & VE components.
A couple of things jump out, an Encoded Vector Index (EVI) that include aggregates(count,min,max) might help here...
select soord stoporder
,count(*) stopsremain
,min(sostp#) nextstop
,max(soappr) apptreq
from pavt.stop
And index (or two) with derived columns substr(order_number,....) might help here:
from inprogress
inner join iesqafile.psmainorvw a
on diodr# = order_number
and didisp = number_disp
and (substr(order_number, 1, 2) <> 'DH'
and substr(order_number, 1, 1) <> 'M')
Again VE is your friend, you'll have to dig into what's going on and where the time is being spent.
Break the various parts of your statement down and try to optimize individual components when possible. Hopefully, the gains will remain when you put it back together.
One thing to remember, a view is performance neutral. It neither helps nor hurts performance.
You don't give an example of how you access the view, but have you considered making use of user defined table functions (UDTF)? While the query engine attempts to push down selection criteria, a UDTF's parameters make it easy for you to explicitly include selection criteria. You might even benefit from encapsulating the statement in a UDTF and building the view over the UDTF. You can see an example (via Generate SQL Source) for the message_queue_info view & UDTF in QSYS2 that IBM provided.

(Laravel) how to sum a data from table and save the result in another one?

i'm using Laravel to build a quizzes database ( API) and i have the following table :
(id , student , question , category , points )
each question is belong to a specific category and it has a points value , for example :
id = 1 , student = Jack , question = 'What is the color of the milk' , category = Easy , points : 2.
id = 1 , student = Jack , question = 'What is the width of the car door' , category = medium , points : 5.
id = 2 , student = fareed ,question = ' what is the age of lionel Messi' , category = Hard , points: 3
and so on ,
what i want to do is to get the sum of the points belongs to the same category from the above table and store the result of the sum in another table like :
id= 1 , student : jack , easySumPoint = 30 , midSumPoint = 43 , HardSumPoint= 60
id=2 , student : fareed , easySumPoint = 21 , midSumPoint = 55 , HardSumPoint= 7
and so on
how i can do that ?
you can try something like this
Model::groupBy('student')
->selectRaw('sum(points) as sum, student')
->lists('sum','student');

Error Calling DB2 Stored Procedure

I defined a stored procedure with input and output parameters and am getting the following error when I try to call the stored procedure.
[SQL0312] Variable KUNNR not defined or not usable.
Here is the call:
CALL R3QA6DATA.SP_ADDRESS_CHANGES ('1999-12-31 23:59:59', '2016-06-01 23:59:59', :KUNNR,:KUNN2,:NAME1,:NAME2,:STRAS,:ORT01,:REGIO,:PSTLZ,:LAND1,:TELF1,:TELFX,:DEFPA)
GO
Here is the stored procedure:
CREATE PROCEDURE R3QA6DATA.SP_ADDRESS_CHANGES
(IN STARTDATE TIMESTAMP, IN ENDDATE TIMESTAMP,
OUT KUNNR GRAPHIC(10), OUT KUNN2 GRAPHIC(10), OUT NAME1 GRAPHIC(35), OUT NAME2 GRAPHIC(35), OUT STRAS GRAPHIC(35), OUT ORT01 GRAPHIC(35),
OUT REGIO GRAPHIC(3), OUT PSTLZ GRAPHIC(10), OUT LAND1 GRAPHIC(3), OUT TELF1 GRAPHIC(16), OUT TELFX GRAPHIC(31), OUT DEFPA GRAPHIC(1) )
LANGUAGE SQL
BEGIN
SELECT DISTINCT
knvp.kunnr
, knvp.kunn2
, kna1.name1
, kna1.name2
, kna1.stras
, kna1.ort01
, kna1.regio
, kna1.pstlz
, kna1.land1
, kna1.telf1
, kna1.telfx
, knvp.defpa
INTO KUNNR, KUNN2, NAME1, NAME2, STRAS, ORT01, REGIO, PSTLZ, LAND1, TELF1, TELFX, DEFPA
FROM
R3QA6DATA.KNA1 AS kna1
INNER JOIN
R3QA6DATA.ZMBCM AS zmbcm
ON
kna1.KUNNR = zmbcm.KUNAG
INNER JOIN
R3QA6DATA.KNVV AS knvv
ON
( kna1.KUNNR = knvv.KUNNR )
INNER JOIN
R3QA6DATA.KNVP AS knvp
ON
(
knvv.KUNNR = knvp.KUNNR
AND
knvv.VKORG = knvp.VKORG
AND
knvv.VTWEG = knvp.VTWEG
AND
knvv.SPART = knvp.SPART
)
WHERE
kna1.MANDT = '010'
AND
knvp.PARVW IN ('WE', 'AG')
AND
(
knvv.VKORG = zmbcm.VKORG
AND
knvv.VTWEG = zmbcm.VTWEG
AND
knvv.SPART = zmbcm.SPART
)
AND
kna1.loevm = ' '
AND
knvv.loevm = ' '
AND
knvp.KUNN2 IN
(
SELECT
SUBSTRING(bdcp2.tabkey, 4, 10)
FROM
R3QA6DATA.BDCP2 AS bdcp2
WHERE
bdcp2.mestype = 'DEBMAS'
AND
(
( bdcp2.tabname = 'KNA1'
AND
bdcp2.fldname IN
('NAME1'
, 'NAME2'
, 'STRAS'
, 'ORT01'
, 'REGIO'
, 'LAND1'
, 'PSTLZ'
, 'TELF1'
, 'TELFX') )
OR
( bdcp2.tabname = 'KNVP' )
)
AND
(
bdcp2.cretime > STARTDATE
AND
bdcp2.cretime < ENDDATE
)
)
AND
zmbcm.STOREID = 4 ;
END
Go
In RPGLE or COBOL this issue usually happens if you have the variables defined in an external source and accessed through COPY statement. If this is the case in your problem then try using the source through INCLUDE.

Conversion from Oracle into SQL Server

I am trying to interpret Oracle script into SQL script and I see that I am converting the joins wrong as Oracle is using multiple instances of the same table(see orguserfield_c, orguserfield_e, etc in select statment). Could anyone please help me in converting the Oracle into SQL script. Thanks
ORACLE SCRIPT:
select distinct
wh_acctcommon.effdate
, wh_acctcommon.acctnbr
, wh_acctcommon.acctclosecurrmonthyn
, wh_acctcommon.acctofficer
, wh_acctcommon.acctofficernbr
, wh_acctcommon.acctopencurrmonthyn
, wh_acctcommon.notebal
, wh_acctcommon.branchname
, wh_acctcommon.branchorgnbr
, orguserfield_c.value branch_internal_no
, orguserfield_e.value branch_status
, orguserfield_h.value branch_hub_no
, orguserfield_i.value metro_micro
, orguserfield_j.value division
, userfieldvalue_l.userfieldvaluedesc division_name
, orguserfield.value region
, userfieldvalue.userfieldvaluedesc region_name
, wh_acctcommon.primaryownercity
, wh_acctcommon.closedate
, wh_acctcommon.compoundcalpercd
, wh_acctcommon.contractdate
, wh_acctcommon.datelastmaint
, wh_acctcommon.ownername
, wh_acctcommon.bankorgnbr
, wh_acctcommon.intbase
, wh_acctcommon.intmethcd
, wh_acctcommon.noteintrate
, wh_acctcommon.ownersortname
, wh_acctcommon.loanofficer
, wh_acctcommon.loanofficersnbr
, wh_acctcommon.mjaccttypcd
, wh_acctcommon.managingofficer
, wh_acctcommon.managingofficernbr
, acctacctrolepers.persnbr SBB_Portfolio_Mgr_Nbr
, persview.fullname SBB_Portfolio_Mgr
, acctacctrolepers_c.persnbr Orig_Loan_Officer_Nbr
, persview_d.fullname Orig_Loan_Officer
, acctacctrolepers_e.persnbr Collection_Officer_Nbr
, persview_e.fullname Collection_Officer
, wh_acctcommon.datemat
, wh_acctcommon.intminbalamt
, wh_acctcommon.intmincalcbaltypcd
, wh_acctcommon.monthendyn
, wh_acctcommon.notemtdavgbal
, wh_acctcommon.nameaddr1
, wh_acctcommon.nameaddr2
, wh_acctcommon.nameaddr3
, wh_acctcommon.nameaddr4
, wh_acctcommon.nameaddr5
, wh_acctcommon.notenextratechangedate
, wh_acctcommon.noteopenamt
, wh_acctcommon.originatingperson
, wh_acctcommon.origpersnbr
, wh_acctcommon.bookbalance
, wh_acctcommon.businessphone
, wh_acctcommon.homephone
, wh_acctcommon.currmiaccttypcd
, wh_acctcommon.product
, wh_acctcommon.calcbaltypcd
, wh_acctcommon.noteratechangecalpercd
, wh_acctcommon.daysmethcd
, wh_acctcommon.noteintcalcschednbr
, wh_acctcommon.ratetypcd
, wh_acctcommon.primaryownerstate
, wh_acctcommon.curracctstatcd
, wh_acctcommon.curracctstateffdate
, wh_acctcommon.taxidnbr
, wh_acctcommon.taxrptfororgnbr
, wh_acctcommon.taxrptforpersnbr
, wh_acctcommon.currterm
, wh_acctcommon.primaryownerzipcd
, wh_acctcommon.primaryownerzipcdsuff
from OSIBANK.wh_acctcommon
, OSIBANK.orguserfield
, OSIBANK.orguserfield orguserfield_c
, OSIBANK.orguserfield orguserfield_e
, OSIBANK.orguserfield orguserfield_h
, OSIBANK.orguserfield orguserfield_i
, OSIBANK.orguserfield orguserfield_j
, OSIBANK.userfieldvalue
, OSIBANK.userfieldvalue userfieldvalue_l
, OSIBANK.acctacctrolepers
, OSIBANK.persview
, OSIBANK.acctacctrolepers acctacctrolepers_c
, OSIBANK.persview persview_d
, OSIBANK.acctacctrolepers acctacctrolepers_e
, OSIBANK.persview persview_e
where ( wh_acctcommon.branchorgnbr = orguserfield.orgnbr(+)
and upper(orguserfield.userfieldcd(+)) = 'WREG'
and orguserfield.userfieldcd = userfieldvalue.userfieldcd(+)
and orguserfield.value = userfieldvalue.userfieldvalue(+)
)
and ( wh_acctcommon.branchorgnbr = orguserfield_c.orgnbr(+)
and upper(orguserfield_c.userfieldcd(+)) = 'WBRN'
)
and ( wh_acctcommon.branchorgnbr = orguserfield_e.orgnbr(+)
and upper(orguserfield_e.userfieldcd(+)) = 'WBRS'
)
and ( wh_acctcommon.branchorgnbr = orguserfield_h.orgnbr(+)
and upper(orguserfield_h.userfieldcd(+)) = 'WHBN'
)
and ( wh_acctcommon.branchorgnbr = orguserfield_i.orgnbr(+)
and upper(orguserfield_i.userfieldcd(+)) = 'WSIZ'
)
and ( wh_acctcommon.branchorgnbr = orguserfield_j.orgnbr(+)
and upper(orguserfield_j.userfieldcd(+)) = 'WDIV'
and orguserfield_j.userfieldcd = userfieldvalue_l.userfieldcd(+)
and orguserfield_j.value = userfieldvalue_l.userfieldvalue(+)
)
and ( wh_acctcommon.acctnbr = acctacctrolepers.acctnbr(+)
and upper(acctacctrolepers.acctrolecd(+)) = 'PMGR'
and acctacctrolepers.persnbr = persview.persnbr(+)
)
and ( wh_acctcommon.acctnbr = acctacctrolepers_c.acctnbr(+)
and acctacctrolepers_c.acctrolecd(+) = 'OLOF'
and acctacctrolepers_c.persnbr = persview_d.persnbr(+)
)
and ( wh_acctcommon.acctnbr = acctacctrolepers_e.acctnbr(+)
and acctacctrolepers_e.acctrolecd(+) = 'COFF'
and acctacctrolepers_e.persnbr = persview_e.persnbr(+)
);
SQL SCRIPT:
select
wh_acctcommon.[EFFDATE]
, wh_acctcommon.acctnbr
, wh_acctcommon.acctclosecurrmonthyn
, wh_acctcommon.acctofficer
, wh_acctcommon.acctofficernbr
, wh_acctcommon.acctopencurrmonthyn
, wh_acctcommon.notebal
, wh_acctcommon.branchname
, wh_acctcommon.branchorgnbr
,OUF.value AS 'branch_internal_no'
, OUF.value AS 'branch_status'
, OUF.value AS 'branch_hub_no'
, OUF.value AS 'metro_micro'
, OUF.value AS 'division'
, UFV.[USERFIELDVALUEDESC] AS 'division_name'
, OUF.value AS 'region'
, UFV.userfieldvaluedesc AS 'region_name'
, wh_acctcommon.primaryownercity
, wh_acctcommon.closedate
, wh_acctcommon.compoundcalpercd
, wh_acctcommon.contractdate
, wh_acctcommon.datelastmaint
, wh_acctcommon.ownername
, wh_acctcommon.bankorgnbr
, wh_acctcommon.intbase
, wh_acctcommon.intmethcd
, wh_acctcommon.noteintrate
, wh_acctcommon.ownersortname
, wh_acctcommon.loanofficer
, wh_acctcommon.loanofficersnbr
, wh_acctcommon.mjaccttypcd
, wh_acctcommon.managingofficer
, wh_acctcommon.managingofficernbr
, AARP.persnbr AS 'SBB_Portfolio_Mgr_Nbr'
, PV.fullname as 'SBB_Portfolio_Mgr'
, AARP.persnbr AS 'Orig_Loan_Officer_Nbr'
, PV.fullname AS 'Orig_Loan_Officer'
, AARP.persnbr as 'Collection_Officer_Nbr'
, PV.fullname AS 'Collection_Officer'
, wh_acctcommon.datemat
, wh_acctcommon.intminbalamt
, wh_acctcommon.intmincalcbaltypcd
, wh_acctcommon.monthendyn
, wh_acctcommon.notemtdavgbal
, wh_acctcommon.nameaddr1
, wh_acctcommon.nameaddr2
, wh_acctcommon.nameaddr3
, wh_acctcommon.nameaddr4
, wh_acctcommon.nameaddr5
, wh_acctcommon.notenextratechangedate
, wh_acctcommon.noteopenamt
, wh_acctcommon.originatingperson
, wh_acctcommon.origpersnbr
, wh_acctcommon.bookbalance
, wh_acctcommon.businessphone
, wh_acctcommon.homephone
, wh_acctcommon.currmiaccttypcd
, wh_acctcommon.product
, wh_acctcommon.calcbaltypcd
, wh_acctcommon.noteratechangecalpercd
, wh_acctcommon.daysmethcd
, wh_acctcommon.noteintcalcschednbr
, wh_acctcommon.ratetypcd
, wh_acctcommon.primaryownerstate
, wh_acctcommon.curracctstatcd
, wh_acctcommon.curracctstateffdate
, wh_acctcommon.taxidnbr
, wh_acctcommon.taxrptfororgnbr
, wh_acctcommon.taxrptforpersnbr
, wh_acctcommon.currterm
, wh_acctcommon.primaryownerzipcd
, wh_acctcommon.primaryownerzipcdsuff
FROM
[DNA_Staging].[dbo].[WH_ACCTCOMMON] wh_acctcommon
LEFT OUTER JOIN [DNA_Staging].[dbo].orguserfield OUF
ON wh_acctcommon.branchorgnbr = OUF .orgnbr
and upper(OUF.userfieldcd) IN( 'WREG','WBRN','WBRS','WHBN','WSIZ','WDIV')
LEFT OUTER JOIN [DNA_Staging].[dbo].userfieldvalue UFV
ON OUF.userfieldcd = UFV.userfieldcd
and OUF.value = UFV.userfieldvalue
LEFT OUTER JOIN [DNA_Staging].[dbo].[ACCTACCTROLEPERS] AARP
ON wh_acctcommon.acctnbr = AARP.acctnbr
and upper(AARP.acctrolecd) IN ('PMGR','OLOF','COFF')
LEFT OUTER JOIN [DNA_Cleanup_DM].[dbo].PERSVIEW PV
ON AARP.persnbr = PV.persnbr
This is mostly about converting the pre-SQL99 Oracle proprietary joins into SQL99 joins. Rather than try to convert your actual code, here is some advice:
The number of tables in the from clause should remain exactly the same in both queries. If a table is listed 5 times (with aliases) in the original query, you should have the same 5 instances in the revised query. A fatal flaw with your revised query is that you're trying to collapse these relationships using in. You simply can't do that and retain the meaning of the original query.
Start with the first table and work down, converting each comma in the original from clause into an on.
If a relationship in the original where clause contains the outer join indicator ((+)), then that relationship must go in the outer table's on clause. For instance, a.a = b.a(+) must become left join b on a.a = b.a.

Resources