Sql query unit price
Hello Together,
how can i find the unit price for an item with an query.
I used this query:
SELECT $[$34.0.68] FROM [dbo].[OITM]
WHERE
OITM.ItemCode = '10000-0000'
but with the result '0' as price but in the item i have 5 $ as unit price.
Thank you and best regards
Edited by: Serkan Er on Oct 22, 2009 1:59 PM
OH ok,
i just want possibilitty to select the actual unit Price from the item master data.
In the item master data we put in the field Price_List: pricelist_1.
Concerning this field the system shows us the Unit-Price for this item which is in the pricelist_1.
In SQL i can find a table named OPLN - the records are only the information pricelist1, pricelist2 , e.g.
how can i find the details to this records - for example pricelist_1
is there a related table ????????????????
Similar Messages
-
SQL Query Calculating Price based on logic
Hi Experts,
Here is my table records,
SHIPMENT_ID SHIP_PRICE SHIP_ADDT_PRICE PRODUCT_ID PRODUCT_QTY
1000 3.95 1 12 2
1000 0 0 17 1
1000 6.95 2 11 4
1001 0 0 17 1
1001 12.95 1 12 2
1001 12.95 2 11 4
1002 0 0 17 1
1002 20.95 1 12 2
1002 20.95 2 11 4For Each Shipment:
I need to get maximum shipprice (no need to consider product and qty).
then to manipulate as follows from existing sample records such as
SHIPMENT_ID SHIP_PRICE
1000 (1*6.95)+(4-1*2) -- Maximum Price Calculation for particular shipment
1000 (1*0) -- Other product calculation for same shipment
1000 (4*2) -- Other product calculation for same shipment
1001 (1*12.95)+(4-1*2) -- Maximum Price Calculation for particular shipment
1001 (1*0) -- Other product calculation for same shipment
1001 (4*2) -- Other product calculation for same shipment
1002 (1*20.95)+(4-1*2) -- Maximum Price Calculation for particular shipment
1002 (1*0) -- Other product calculation for same shipment
1002 (4*2) -- Other product calculation for same shipment
Max Shipprice Row for each Shipment
(SHIP_PRICE)+(remaining PRODUCT_QTY if PRODUCT_QTY>1 + SHIP_ADDT_PRICE)
Other than Max shipprice for each shipment
(PRODUCT_QTY + SHIP_ADDT_PRICE)
I am struggling here with logic how to proceed it, Any suggestions related to this?
Thanks,Hi,
Sorry to disturb you again, it seems the requirement is not met correct.
The given answer just worked out for that data. May be i have not conveyed correctly.
Here is what i need
Table Records
SHIPMENT_ID SHIPMENT_PRICE SHIPMENT_ADDT_PRICE PRODUCT_ID PRODUCT_QTY VIRTUAL_COLUMN (Just for your Reference)
1000 6.95 2 11 4 1
1000 6.95 2 11 4 2
1000 3.95 1 13 2 3
1000 3.95 1 12 2 4
1001 12.95 2 11 4 5
1001 12.95 1 13 2 6
1001 12.95 2 11 4 7
1001 12.95 1 12 2 8
1002 20.95 1 12 2 9
1002 20.95 2 11 4 10
1002 20.95 2 11 4 11
1002 20.95 1 13 2 12
Repeated values in table with Maximum Value,
SHIPMENT_ID SHIP_PRICE SHIPMENT_ADDT_PRICE PRODUCT_QTY PRODUCT_ID VIRTUAL_COLUMN
1000 6.95 2 4 11 1
1000 6.95 2 4 11 2
1001 12.95 2 4 11 5
1001 12.95 2 4 11 7
1002 20.95 2 4 11 10
1002 20.95 2 4 11 11*
In this Case, There are two rows same with maximum value for all three shipments,
but need to take one row as maximum and to consider the other as like not maximum row to process the logic
I have considered the Record with VIRTUAL_COLUMN value 1,5 and 10 as maximum value and others as not maximum values
Expected Result (For Each Row) - Just listed for one shipment_id = 1000 here
SHIPMENT_ID SHIP_PRICE CALCULATION STEPS VIRTUAL_COLUMN
1000 41.7 (1*6.95)+((4-1)*2) Maximum ShipPrice + (PRODUCT_QTY-1)*SHIPMENT_ADDT_PRICE 1
1000 8 (4*2) PRODUCT_QTY*SHIPMENT_ADDT_PRICE 2
1000 2 (2*1) PRODUCT_QTY*SHIPMENT_ADDT_PRICE 3
1000 2 (2*1) PRODUCT_QTY*SHIPMENT_ADDT_PRICE 4*Note: The virtual column in the provided data is just for reference and not exists in table -
Terms user query Changes in unit price in purchase order and a/p invoice
Dear sir
please give me a term user query for , if any changes in unit price in purchase order and a/p invoiceHi,
Try this:
SELECT Distinct ' true'
FROM adoc T2
JOIN ado1 T0 ON T2.docentry = T0.docentry AND T2.Objtype = '22'
JOIN por1 T1 ON T1.docentry = T0.docentry AND T1.Linenum=T0.Linenum
WHERE $[$38.14.number] != T0.Price
Thanks & Regards,
Nagarajan -
Query base approval for PO Unit Price
Dear All,
I want a Query Base approval
Scenario: If Purchase Order Unit Price Exceed form 10000/- INR then Purchase Order Goes to the Approval
Do any one have a Query base approval for above Scenario?In an approval query you can not access all the row level data. (Only the first line.) So you can not connect your approval on row level conditions.
I can suggest one (but a little uncomfortable and complicated) workaround for approval on line level:
1. Create a header level UDF e.g. named ForApproval with possible values Y and N, with default value N.
2. Write code in the SBO_SP_TransactionNotification stored procedure, that signals an error message u2018You should set ForApproval to Y!u2019 if U_ForApproval=u2019Nu2019 and there is any line with fulfilling your criteria.
3. Set an approval procedure according to the header level ForApproval field. -
FMS Query to Validate Unit Price on PO Screen
Hello Experts,
I am hoping someone has come across a query like this.
On the Purchase Order I want to validate the unit price field by running a FMS query against it.
What I would like to be able to do is :
(Qty Field) X (UDF field which would be weight) X the list price of the item on the line
So Qty 10 X the UDF field which is 1 X the List Unit Price of the item which then goes into the Unit Price field after the FMS query has run.
Is this possible?
At the moment I can run it against the unit price in the field but obviously this does not check the unit price from the Pricelist
SELECT $[$38.14.number] * $[POR1.Quantity.number] * $[POR1.U_U_Weight]
Although this works the first time you run it - it calculates correctly but if you run the fms again it keep mulitplying the figure - is there a way to stop this
Any suggestions would be appreciated
thanksHi Rahul,
The code in the first message got messed up -
However here it is -
SELECT $[$38.14.number] * $[POR1.Quantity.number] * $[POR1.U_U_Weight]
I also tried your code and get the same result - the first time you run it it calculates the amount ok.
But it does not stop at that point - if you click on the FMS link again it takes what is in the unit price field and calculates it again - so it will keep going which is not ideal.
More importantly though
Is there a way I can get the query to check the list price for the item first and then multiply it X Qty and then by the Udf Field which is weight -
Query for Difference in LPP of SO and Unit Price of PO
Dear Experts,
I have the following query which gives me the link between SO and PO.
I have the Last purchase price from SO also. Below is the query
SELECT T0.[DocEntry],T0.[DocNum] as 'SONumber',T1.[GrossBuyPr] as 'Last Purchase Price',T1.[PoTrgNum] as 'PO Number',
T2.[firstName] FROM ORDR T0 INNER JOIN RDR1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN OHEM T2 ON T0.OwnerCode =
T2.empID WHERE T0.[DocDate] >=[%0] AND T0.[DocDate] <=[%1]
What I want is the Unit price of the PO to appear and also difference in value of LPP of SO and Unit Price of PO should come in separate column.
Is it possible to get Please let me know about it
Thanks&Regards
Darshan DesaiHi,
Try this:
SELECT T0.[DocEntry], T0.[DocNum], T1.[GrossBuyPr], T2.[DocNum], T3.[Price],T1.[GrossBuyPr] - T3.[Price] FROM ORDR T0 INNER JOIN RDR1 T1 ON T0.DocEntry = T1.DocEntry left join OPOR T2 on T2.[DocNum] = T1.[PoTrgNum] INNER JOIN POR1 T3 ON T2.DocEntry = T3.DocEntry WHERE T1.[ItemCode] = T3.[ItemCode] and T0.[DocDate] between [%0] and [%1]
Thanks & Regards,
Nagarajan -
Hey,
Please forgive me if I'm missing something really obvious but it's been a while since I did any SQL work and I'm obviously a bit rusty.
When the below query is run the CPU on the SQL server maxes out. The query itself takes over 6 hours to run.
Is there anything glaringly obvious with the query that might be causing thisCheers
Paul
SELECT TOP (100) PERCENT dbo.CUSTPACKINGSLIPTRANS.ITEMID AS [Stock Code],
dbo.CUSTPACKINGSLIPTRANS.SALESUNIT AS [Unit of Sale],
dbo.DIMENSIONFINANCIALTAG.DESCRIPTION AS [Product Group],
dbo.INVENTITEMGROUP.ITEMGROUPID AS [Item Group],
dbo.INVENTTABLE.SECTION,
dbo.INVENTTABLE.GROUPS AS [Group],
dbo.INVENTTABLE.SUBGROUPS AS [Sub Group],
dbo.CUSTPACKINGSLIPJOUR.ORDERACCOUNT AS [Cust Account],
dbo.CUSTTABLE.INVOICEACCOUNT AS [Invoice Account],
dbo.DIRPARTYTABLE.NAME AS [Cust Name],
dbo.CUSTTABLE.CURRENCY,
dbo.CUSTTABLE.CIT_CONTROLLER AS [Credit Controller],
dbo.CUSTTABLE.CREDITMAX AS [Credit Limit],
dbo.CUSTTABLE.CUSTCLASSIFICATIONID AS Classification,
dbo.DIRPERSONNAME.FIRSTNAME + ' ' + dbo.DIRPERSONNAME.LASTNAME AS [Sales Person],
dbo.SALESTABLE.SALESGROUP AS [Outside Rooms],
CASE WHEN CUSTTABLE.CUSTCLASSIFICATIONID = 'Cash' THEN dbo.SALESTABLE.SALESGROUP ELSE dbo.CUSTTABLE.SALESGROUP END AS [Sales Rep],
dbo.LOGISTICSPOSTALADDRESS.STATE [Customer Region],
dbo.LOGISTICSPOSTALADDRESS.COUNTY [Customer County],
dbo.CUSTTABLE.LINEOFBUSINESSID AS [Line Of Business],
a.DISPLAYVALUE AS [Site/Location],
dbo.CUSTPACKINGSLIPTRANS.PACKINGSLIPID AS [Delivery Ref],
dbo.LOGISTICSPOSTALADDRESS.COUNTRYREGIONID,
CONVERT(varchar(12), dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE, 111) AS [Delivery Date],
dbo.LOGISTICSPOSTALADDRESS.ADDRESS AS [Delivery Address],
dbo.CUSTPACKINGSLIPTRANS.VALUEMST AS [Delivery Value (CON)],
CONVERT(varchar(12), dbo.SALESTABLE.RECEIPTDATEREQUESTED, 111) AS [Requested Delivery Date],
dbo.SALESTABLE.SALESID AS [Order Ref],
CASE dbo.SALESTABLE.SALESSTATUS WHEN '0' THEN 'None' WHEN '1' THEN 'Open Order' WHEN '2' THEN 'Delivered' WHEN '3' THEN 'Invoiced' WHEN '4' THEN 'Canceled' END AS [Sales Status],
CASE dbo.SALESTABLE.SALESTYPE WHEN '0' THEN 'Journal' WHEN '1' THEN 'Quotation' WHEN '2' THEN 'Subscription' WHEN '3' THEN 'Sales Order' WHEN '4' THEN 'Returned Item' WHEN '5' THEN 'Blanket Order' WHEN '6' THEN 'Item Requirements' WHEN '7' THEN 'Undefined' END AS [Sales Type],
CASE dbo.SALESTABLE.AG_SALESLOCATION WHEN '0' THEN 'None' WHEN '1' THEN 'OR_DGN' WHEN '2' THEN 'OR_FMT' WHEN '3' THEN 'OR_TME' WHEN '4' THEN 'OR_OMA' WHEN '5' THEN 'DSP_DGN' WHEN '6' THEN 'DSP_FMT' WHEN '7' THEN 'DSP_TME' WHEN '8' THEN 'DSP_OMA' WHEN '9' THEN 'DSP_BEL' WHEN '10' THEN 'DSP_CDF' WHEN '11' THEN 'DSP_BGY' WHEN '12' THEN 'Credit Control' WHEN '13' THEN 'Internal Sales' WHEN '14' THEN 'CP_FMT' WHEN '15' THEN 'GBSales' END AS [Sales Location],
dbo.SALESTABLE.PURCHORDERFORMNUM AS [Customer Requisition],
dbo.SALESLINE.LINEDISC AS [Line Disc],
dbo.SALESLINE.LINEPERCENT AS [Line Percent],
dbo.SALESLINE.PRICEGROUPID AS [Price Group],
dbo.INVENTDIM.INVENTLOCATIONID AS Warehouse,
dbo.DIRPARTYTABLE.NAMEALIAS AS [Search Name],
dbo.CUSTPACKINGSLIPJOUR.LORRYID AS [Lorry ID],
dbo.CUSTPACKINGSLIPJOUR.LORRYREGNO AS [Lorry Reg],
dbo.CUSTPACKINGSLIPJOUR.LORRYDRIVER AS [Lorry Driver],
CASE dbo.SALESLINE.BLOCKED WHEN '0' THEN 'No' WHEN '1' THEN 'Yes' END AS [Stopped?],
dbo.CUSTPACKINGSLIPTRANS.QTY AS [Qty Delivered],
dbo.SALESLINE.SALESPRICE AS [Unit Price],
dbo.CUSTPACKINGSLIPJOUR.CREATEDBY AS [SDN Creator],
MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) AS Month,
YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) AS Year,
DATEPART(week, dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) AS WeekNo,
CASE MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) WHEN '1' THEN '10' WHEN '2' THEN '11' WHEN '3' THEN '12' WHEN '4' THEN '1' WHEN '5' THEN '2' WHEN '6' THEN '3' WHEN '7' THEN '4' WHEN '8' THEN '5' WHEN '9' THEN '6' WHEN '10' THEN '7' WHEN '11' THEN '8' WHEN '12' THEN '9' END AS [Fin Period], CASE WHEN MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) <= '3' THEN CONVERT(VARCHAR(10), (YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) - 1)) + '/' + CONVERT(VARCHAR(10), YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE)) WHEN MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) >= '4' THEN CONVERT(VARCHAR(10), YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE)) + '/' + CONVERT(VARCHAR(10), (YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) + 1)) END AS [Fin Year],
CASE WHEN dbo.custpackingsliptrans.salesunit = '100' THEN dbo.CUSTPACKINGSLIPTRANS.SALESUNIT * dbo.CUSTPACKINGSLIPTRANS.QTY WHEN dbo.custpackingsliptrans.salesunit = '1000' THEN dbo.CUSTPACKINGSLIPTRANS.SALESUNIT * dbo.CUSTPACKINGSLIPTRANS.QTY ELSE dbo.CUSTPACKINGSLIPTRANS.QTY END AS [No of Units],
CASE dbo.INVENTITEMGROUPITEM.ITEMGROUPID WHEN 'Mortar' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) WHEN 'Sand' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) WHEN 'Decorative Gravel' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) WHEN 'Crushed Aggregates' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) WHEN 'Lintels' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) / 1000 WHEN 'TBeams' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) / 1000 WHEN 'Aggregates' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) WHEN 'Lime' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY * dbo.UNITOFMEASURECONVERSION.FACTOR) WHEN 'Readymix' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) / 1000 ELSE (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY * dbo.UNITOFMEASURECONVERSION.FACTOR) / 1000 END AS Tonnage,
dbo.INVENTTABLE.NETWEIGHT AS [Net Weight],
dbo.INVENTTABLE.PRODCOSTA,
dbo.INVENTTABLE.PRODCOSTB,
dbo.INVENTTABLE.PRODCOSTC,
dbo.INVENTTABLE.PRODCOSTD,
dbo.INVENTTABLE.PRODCOSTE,
dbo.INVENTTABLE.PRODCOSTF,
dbo.INVENTTABLE.PRODCOSTG,
dbo.INVENTTABLE.PRODCOSTH,
dbo.INVENTTABLE.QTYPERBALE,
dbo.INVENTTABLE.M2PERBALE,
dbo.SALESTABLE.SALESTYPE,
dbo.SALESTABLE.DLVMODE AS [Delivery Mode],
CONVERT(varchar(12), dbo.SALESTABLE.SHIPPINGDATECONFIRMED, 111) AS [Shipping Date Confirmed],
CONVERT(varchar(12), dbo.SALESTABLE.CREATEDDATETIME, 111) AS [Created Date],
dbo.SALESLINE.CUSTGROUP AS [Cust Group],
dbo.INVENTTABLE.MADETOORDER AS [Made To Order]
FROM dbo.CUSTPACKINGSLIPTRANS INNER JOIN
dbo.CUSTPACKINGSLIPJOUR ON dbo.CUSTPACKINGSLIPTRANS.PACKINGSLIPID = dbo.CUSTPACKINGSLIPJOUR.PACKINGSLIPID INNER JOIN
dbo.SALESLINE ON dbo.CUSTPACKINGSLIPJOUR.SALESID = dbo.SALESLINE.SALESID AND
dbo.CUSTPACKINGSLIPTRANS.INVENTTRANSID = dbo.SALESLINE.INVENTTRANSID INNER JOIN
dbo.INVENTTABLE ON dbo.CUSTPACKINGSLIPTRANS.ITEMID = dbo.INVENTTABLE.ITEMID INNER JOIN
dbo.INVENTITEMGROUPITEM ON dbo.INVENTTABLE.ITEMID = dbo.INVENTITEMGROUPITEM.ITEMID INNER JOIN
dbo.INVENTITEMGROUP ON dbo.INVENTITEMGROUPITEM.ITEMGROUPID = dbo.INVENTITEMGROUP.ITEMGROUPID INNER JOIN
dbo.INVENTDIM ON dbo.SALESLINE.INVENTDIMID = dbo.INVENTDIM.INVENTDIMID INNER JOIN
dbo.CUSTTABLE ON dbo.CUSTPACKINGSLIPJOUR.ORDERACCOUNT = dbo.CUSTTABLE.ACCOUNTNUM INNER JOIN
dbo.DIRPARTYTABLE ON dbo.CUSTTABLE.PARTY = dbo.DIRPARTYTABLE.RECID INNER JOIN
dbo.LOGISTICSPOSTALADDRESS ON dbo.DIRPARTYTABLE.PRIMARYADDRESSLOCATION = dbo.LOGISTICSPOSTALADDRESS.LOCATION INNER JOIN
dbo.SALESTABLE ON dbo.SALESLINE.SALESID = dbo.SALESTABLE.SALESID INNER JOIN
dbo.DIRPERSONNAME ON dbo.SALESTABLE.WORKERSALESTAKER = dbo.DIRPERSONNAME.RECID INNER JOIN
dbo.ECORESPRODUCT ON dbo.CUSTPACKINGSLIPTRANS.ITEMID = dbo.ECORESPRODUCT.SEARCHNAME
AND dbo.INVENTTABLE.ITEMID = dbo.ECORESPRODUCT.DISPLAYPRODUCTNUMBER LEFT OUTER JOIN
dbo.UNITOFMEASURECONVERSION ON dbo.ECORESPRODUCT.RECID = dbo.UNITOFMEASURECONVERSION.PRODUCT LEFT OUTER JOIN
dbo.UNITOFMEASURE ON dbo.UNITOFMEASURECONVERSION.TOUNITOFMEASURE = dbo.UNITOFMEASURE.RECID INNER JOIN
dbo.DEFAULTDIMENSIONVIEW a ON dbo.CUSTPACKINGSLIPTRANS.DEFAULTDIMENSION = a.DEFAULTDIMENSION AND a.NAME = 'Department' LEFT OUTER JOIN
dbo.DEFAULTDIMENSIONVIEW b ON dbo.INVENTTABLE.DEFAULTDIMENSION = b.DEFAULTDIMENSION AND b.NAME = 'Center' INNER JOIN
dbo.DIMENSIONFINANCIALTAG ON b.ENTITYINSTANCE = dbo.DIMENSIONFINANCIALTAG.RECID
WHERE (dbo.CUSTPACKINGSLIPTRANS.DATAAREAID = 'agl') AND
(dbo.CUSTPACKINGSLIPJOUR.DATAAREAID = 'agl') AND
(dbo.SALESLINE.DATAAREAID = 'agl') AND
(dbo.INVENTTABLE.DATAAREAID = 'vuk') AND
(dbo.INVENTDIM.DATAAREAID = 'agl') AND
(dbo.CUSTTABLE.DATAAREAID = 'agl') AND
(dbo.SALESTABLE.DATAAREAID = 'agl') AND
(CASE WHEN MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) <= '3' THEN (YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) - 1)
WHEN MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) >= '4' THEN YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) END = 2014)Hey,
Please forgive me if I'm missing something really obvious but it's been a while since I did any SQL work and I'm obviously a bit rusty.
When the below query is run the CPU on the SQL server maxes out. The query itself takes over 6 hours to run.
Is there anything glaringly obvious with the query that might be causing thisCheers
Paul
SELECT TOP (100) PERCENT dbo.CUSTPACKINGSLIPTRANS.ITEMID AS [Stock Code],
dbo.CUSTPACKINGSLIPTRANS.SALESUNIT AS [Unit of Sale],
dbo.DIMENSIONFINANCIALTAG.DESCRIPTION AS [Product Group],
dbo.INVENTITEMGROUP.ITEMGROUPID AS [Item Group],
dbo.INVENTTABLE.SECTION,
dbo.INVENTTABLE.GROUPS AS [Group],
dbo.INVENTTABLE.SUBGROUPS AS [Sub Group],
dbo.CUSTPACKINGSLIPJOUR.ORDERACCOUNT AS [Cust Account],
dbo.CUSTTABLE.INVOICEACCOUNT AS [Invoice Account],
dbo.DIRPARTYTABLE.NAME AS [Cust Name],
dbo.CUSTTABLE.CURRENCY,
dbo.CUSTTABLE.CIT_CONTROLLER AS [Credit Controller],
dbo.CUSTTABLE.CREDITMAX AS [Credit Limit],
dbo.CUSTTABLE.CUSTCLASSIFICATIONID AS Classification,
dbo.DIRPERSONNAME.FIRSTNAME + ' ' + dbo.DIRPERSONNAME.LASTNAME AS [Sales Person],
dbo.SALESTABLE.SALESGROUP AS [Outside Rooms],
CASE WHEN CUSTTABLE.CUSTCLASSIFICATIONID = 'Cash' THEN dbo.SALESTABLE.SALESGROUP ELSE dbo.CUSTTABLE.SALESGROUP END AS [Sales Rep],
dbo.LOGISTICSPOSTALADDRESS.STATE [Customer Region],
dbo.LOGISTICSPOSTALADDRESS.COUNTY [Customer County],
dbo.CUSTTABLE.LINEOFBUSINESSID AS [Line Of Business],
a.DISPLAYVALUE AS [Site/Location],
dbo.CUSTPACKINGSLIPTRANS.PACKINGSLIPID AS [Delivery Ref],
dbo.LOGISTICSPOSTALADDRESS.COUNTRYREGIONID,
CONVERT(varchar(12), dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE, 111) AS [Delivery Date],
dbo.LOGISTICSPOSTALADDRESS.ADDRESS AS [Delivery Address],
dbo.CUSTPACKINGSLIPTRANS.VALUEMST AS [Delivery Value (CON)],
CONVERT(varchar(12), dbo.SALESTABLE.RECEIPTDATEREQUESTED, 111) AS [Requested Delivery Date],
dbo.SALESTABLE.SALESID AS [Order Ref],
CASE dbo.SALESTABLE.SALESSTATUS WHEN '0' THEN 'None' WHEN '1' THEN 'Open Order' WHEN '2' THEN 'Delivered' WHEN '3' THEN 'Invoiced' WHEN '4' THEN 'Canceled' END AS [Sales Status],
CASE dbo.SALESTABLE.SALESTYPE WHEN '0' THEN 'Journal' WHEN '1' THEN 'Quotation' WHEN '2' THEN 'Subscription' WHEN '3' THEN 'Sales Order' WHEN '4' THEN 'Returned Item' WHEN '5' THEN 'Blanket Order' WHEN '6' THEN 'Item Requirements' WHEN '7' THEN 'Undefined' END AS [Sales Type],
CASE dbo.SALESTABLE.AG_SALESLOCATION WHEN '0' THEN 'None' WHEN '1' THEN 'OR_DGN' WHEN '2' THEN 'OR_FMT' WHEN '3' THEN 'OR_TME' WHEN '4' THEN 'OR_OMA' WHEN '5' THEN 'DSP_DGN' WHEN '6' THEN 'DSP_FMT' WHEN '7' THEN 'DSP_TME' WHEN '8' THEN 'DSP_OMA' WHEN '9' THEN 'DSP_BEL' WHEN '10' THEN 'DSP_CDF' WHEN '11' THEN 'DSP_BGY' WHEN '12' THEN 'Credit Control' WHEN '13' THEN 'Internal Sales' WHEN '14' THEN 'CP_FMT' WHEN '15' THEN 'GBSales' END AS [Sales Location],
dbo.SALESTABLE.PURCHORDERFORMNUM AS [Customer Requisition],
dbo.SALESLINE.LINEDISC AS [Line Disc],
dbo.SALESLINE.LINEPERCENT AS [Line Percent],
dbo.SALESLINE.PRICEGROUPID AS [Price Group],
dbo.INVENTDIM.INVENTLOCATIONID AS Warehouse,
dbo.DIRPARTYTABLE.NAMEALIAS AS [Search Name],
dbo.CUSTPACKINGSLIPJOUR.LORRYID AS [Lorry ID],
dbo.CUSTPACKINGSLIPJOUR.LORRYREGNO AS [Lorry Reg],
dbo.CUSTPACKINGSLIPJOUR.LORRYDRIVER AS [Lorry Driver],
CASE dbo.SALESLINE.BLOCKED WHEN '0' THEN 'No' WHEN '1' THEN 'Yes' END AS [Stopped?],
dbo.CUSTPACKINGSLIPTRANS.QTY AS [Qty Delivered],
dbo.SALESLINE.SALESPRICE AS [Unit Price],
dbo.CUSTPACKINGSLIPJOUR.CREATEDBY AS [SDN Creator],
MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) AS Month,
YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) AS Year,
DATEPART(week, dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) AS WeekNo,
CASE MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) WHEN '1' THEN '10' WHEN '2' THEN '11' WHEN '3' THEN '12' WHEN '4' THEN '1' WHEN '5' THEN '2' WHEN '6' THEN '3' WHEN '7' THEN '4' WHEN '8' THEN '5' WHEN '9' THEN '6' WHEN '10' THEN '7' WHEN '11' THEN '8' WHEN '12' THEN '9' END AS [Fin Period], CASE WHEN MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) <= '3' THEN CONVERT(VARCHAR(10), (YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) - 1)) + '/' + CONVERT(VARCHAR(10), YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE)) WHEN MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) >= '4' THEN CONVERT(VARCHAR(10), YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE)) + '/' + CONVERT(VARCHAR(10), (YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) + 1)) END AS [Fin Year],
CASE WHEN dbo.custpackingsliptrans.salesunit = '100' THEN dbo.CUSTPACKINGSLIPTRANS.SALESUNIT * dbo.CUSTPACKINGSLIPTRANS.QTY WHEN dbo.custpackingsliptrans.salesunit = '1000' THEN dbo.CUSTPACKINGSLIPTRANS.SALESUNIT * dbo.CUSTPACKINGSLIPTRANS.QTY ELSE dbo.CUSTPACKINGSLIPTRANS.QTY END AS [No of Units],
CASE dbo.INVENTITEMGROUPITEM.ITEMGROUPID WHEN 'Mortar' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) WHEN 'Sand' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) WHEN 'Decorative Gravel' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) WHEN 'Crushed Aggregates' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) WHEN 'Lintels' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) / 1000 WHEN 'TBeams' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) / 1000 WHEN 'Aggregates' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) WHEN 'Lime' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY * dbo.UNITOFMEASURECONVERSION.FACTOR) WHEN 'Readymix' THEN (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY) / 1000 ELSE (dbo.INVENTTABLE.NETWEIGHT * dbo.CUSTPACKINGSLIPTRANS.QTY * dbo.UNITOFMEASURECONVERSION.FACTOR) / 1000 END AS Tonnage,
dbo.INVENTTABLE.NETWEIGHT AS [Net Weight],
dbo.INVENTTABLE.PRODCOSTA,
dbo.INVENTTABLE.PRODCOSTB,
dbo.INVENTTABLE.PRODCOSTC,
dbo.INVENTTABLE.PRODCOSTD,
dbo.INVENTTABLE.PRODCOSTE,
dbo.INVENTTABLE.PRODCOSTF,
dbo.INVENTTABLE.PRODCOSTG,
dbo.INVENTTABLE.PRODCOSTH,
dbo.INVENTTABLE.QTYPERBALE,
dbo.INVENTTABLE.M2PERBALE,
dbo.SALESTABLE.SALESTYPE,
dbo.SALESTABLE.DLVMODE AS [Delivery Mode],
CONVERT(varchar(12), dbo.SALESTABLE.SHIPPINGDATECONFIRMED, 111) AS [Shipping Date Confirmed],
CONVERT(varchar(12), dbo.SALESTABLE.CREATEDDATETIME, 111) AS [Created Date],
dbo.SALESLINE.CUSTGROUP AS [Cust Group],
dbo.INVENTTABLE.MADETOORDER AS [Made To Order]
FROM dbo.CUSTPACKINGSLIPTRANS INNER JOIN
dbo.CUSTPACKINGSLIPJOUR ON dbo.CUSTPACKINGSLIPTRANS.PACKINGSLIPID = dbo.CUSTPACKINGSLIPJOUR.PACKINGSLIPID INNER JOIN
dbo.SALESLINE ON dbo.CUSTPACKINGSLIPJOUR.SALESID = dbo.SALESLINE.SALESID AND
dbo.CUSTPACKINGSLIPTRANS.INVENTTRANSID = dbo.SALESLINE.INVENTTRANSID INNER JOIN
dbo.INVENTTABLE ON dbo.CUSTPACKINGSLIPTRANS.ITEMID = dbo.INVENTTABLE.ITEMID INNER JOIN
dbo.INVENTITEMGROUPITEM ON dbo.INVENTTABLE.ITEMID = dbo.INVENTITEMGROUPITEM.ITEMID INNER JOIN
dbo.INVENTITEMGROUP ON dbo.INVENTITEMGROUPITEM.ITEMGROUPID = dbo.INVENTITEMGROUP.ITEMGROUPID INNER JOIN
dbo.INVENTDIM ON dbo.SALESLINE.INVENTDIMID = dbo.INVENTDIM.INVENTDIMID INNER JOIN
dbo.CUSTTABLE ON dbo.CUSTPACKINGSLIPJOUR.ORDERACCOUNT = dbo.CUSTTABLE.ACCOUNTNUM INNER JOIN
dbo.DIRPARTYTABLE ON dbo.CUSTTABLE.PARTY = dbo.DIRPARTYTABLE.RECID INNER JOIN
dbo.LOGISTICSPOSTALADDRESS ON dbo.DIRPARTYTABLE.PRIMARYADDRESSLOCATION = dbo.LOGISTICSPOSTALADDRESS.LOCATION INNER JOIN
dbo.SALESTABLE ON dbo.SALESLINE.SALESID = dbo.SALESTABLE.SALESID INNER JOIN
dbo.DIRPERSONNAME ON dbo.SALESTABLE.WORKERSALESTAKER = dbo.DIRPERSONNAME.RECID INNER JOIN
dbo.ECORESPRODUCT ON dbo.CUSTPACKINGSLIPTRANS.ITEMID = dbo.ECORESPRODUCT.SEARCHNAME
AND dbo.INVENTTABLE.ITEMID = dbo.ECORESPRODUCT.DISPLAYPRODUCTNUMBER LEFT OUTER JOIN
dbo.UNITOFMEASURECONVERSION ON dbo.ECORESPRODUCT.RECID = dbo.UNITOFMEASURECONVERSION.PRODUCT LEFT OUTER JOIN
dbo.UNITOFMEASURE ON dbo.UNITOFMEASURECONVERSION.TOUNITOFMEASURE = dbo.UNITOFMEASURE.RECID INNER JOIN
dbo.DEFAULTDIMENSIONVIEW a ON dbo.CUSTPACKINGSLIPTRANS.DEFAULTDIMENSION = a.DEFAULTDIMENSION AND a.NAME = 'Department' LEFT OUTER JOIN
dbo.DEFAULTDIMENSIONVIEW b ON dbo.INVENTTABLE.DEFAULTDIMENSION = b.DEFAULTDIMENSION AND b.NAME = 'Center' INNER JOIN
dbo.DIMENSIONFINANCIALTAG ON b.ENTITYINSTANCE = dbo.DIMENSIONFINANCIALTAG.RECID
WHERE (dbo.CUSTPACKINGSLIPTRANS.DATAAREAID = 'agl') AND
(dbo.CUSTPACKINGSLIPJOUR.DATAAREAID = 'agl') AND
(dbo.SALESLINE.DATAAREAID = 'agl') AND
(dbo.INVENTTABLE.DATAAREAID = 'vuk') AND
(dbo.INVENTDIM.DATAAREAID = 'agl') AND
(dbo.CUSTTABLE.DATAAREAID = 'agl') AND
(dbo.SALESTABLE.DATAAREAID = 'agl') AND
(CASE WHEN MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) <= '3' THEN (YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) - 1)
WHEN MONTH(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) >= '4' THEN YEAR(dbo.CUSTPACKINGSLIPTRANS.DELIVERYDATE) END = 2014)
Try to minimize joins using intermediary tables, also you can consider limiting data based on date ranges and codes (DATAAREAID) before joining with other tables. -
SQL query performance issues.
Hi All,
I worked on the query a month ago and the fix worked for me in test intance but failed in production. Following is the URL for the previous thread.
SQL query performance issues.
Following is the tkprof file.
CURSOR_ID:76 LENGTH:2383 ADDRESS:f6b40ab0 HASH_VALUE:2459471753 OPTIMIZER_GOAL:ALL_ROWS USER_ID:443 (APPS)
insert into cos_temp(
TRX_DATE, DEPT, PRODUCT_LINE, PART_NUMBER,
CUSTOMER_NUMBER, QUANTITY_SOLD, ORDER_NUMBER,
INVOICE_NUMBER, EXT_SALES, EXT_COS,
GROSS_PROFIT, ACCT_DATE,
SHIPMENT_TYPE,
FROM_ORGANIZATION_ID,
FROM_ORGANIZATION_CODE)
select a.trx_date,
g.segment5 dept,
g.segment4 prd,
m.segment1 part,
d.customer_number customer,
b.quantity_invoiced units,
-- substr(a.sales_order,1,6) order#,
substr(ltrim(b.interface_line_attribute1),1,10) order#,
a.trx_number invoice,
(b.quantity_invoiced * b.unit_selling_price) sales,
(b.quantity_invoiced * nvl(price.operand,0)) cos,
(b.quantity_invoiced * b.unit_selling_price) -
(b.quantity_invoiced * nvl(price.operand,0)) profit,
to_char(to_date('2010/02/28 00:00:00','yyyy/mm/dd HH24:MI:SS'),'DD-MON-RR') acct_date,
'DRP',
l.ship_from_org_id,
p.organization_code
from ra_customers d,
gl_code_combinations g,
mtl_system_items m,
ra_cust_trx_line_gl_dist c,
ra_customer_trx_lines b,
ra_customer_trx_all a,
apps.oe_order_lines l,
apps.HR_ORGANIZATION_INFORMATION i,
apps.MTL_INTERCOMPANY_PARAMETERS inter,
apps.HZ_CUST_SITE_USES_ALL site,
apps.qp_list_lines_v price,
apps.mtl_parameters p
where a.trx_date between to_date('2010/02/01 00:00:00','yyyy/mm/dd HH24:MI:SS')
and to_date('2010/02/28 00:00:00','yyyy/mm/dd HH24:MI:SS')+0.9999
and a.batch_source_id = 1001 -- Sales order shipped other OU
and a.complete_flag = 'Y'
and a.customer_trx_id = b.customer_trx_id
and b.customer_trx_line_id = c.customer_trx_line_id
and a.sold_to_customer_id = d.customer_id
and b.inventory_item_id = m.inventory_item_id
and m.organization_id
= decode(substr(g.segment4,1,2),'01',5004,'03',5004,
'02',5003,'00',5001,5002)
and nvl(m.item_type,'0') <> '111'
and c.code_combination_id = g.code_combination_id+0
and l.line_id = b.interface_line_attribute6
and i.organization_id = l.ship_from_org_id
and p.organization_id = l.ship_from_org_id
and i.org_information3 <> '5108'
and inter.ship_organization_id = i.org_information3
and inter.sell_organization_id = '5108'
and inter.customer_site_id = site.site_use_id
and site.price_list_id = price.list_header_id
and product_attr_value = to_char(m.inventory_item_id)
call count cpu elapsed disk query current rows misses
Parse 1 0.47 0.56 11 197 0 0 1
Execute 1 3733.40 3739.40 34893 519962154 11 188 0
total 2 3733.87 3739.97 34904 519962351 11 188 1
| Rows Row Source Operation
| ------------ ---------------------------------------------------
| 188 HASH JOIN (cr=519962149 pr=34889 pw=0 time=2607.35)
| 741 .TABLE ACCESS BY INDEX ROWID QP_PRICING_ATTRIBUTES (cr=519939426 pr=34889 pw=0 time=2457.32)
| 254644500 ..NESTED LOOPS (cr=519939265 pr=34777 pw=0 time=3819.67)
| 254643758 ...NESTED LOOPS (cr=8921833 pr=29939 pw=0 time=1274.41)
| 741 ....NESTED LOOPS (cr=50042 pr=7230 pw=0 time=11.37)
| 741 .....NESTED LOOPS (cr=48558 pr=7229 pw=0 time=11.35)
| 741 ......NESTED LOOPS (cr=47815 pr=7223 pw=0 time=11.32)
| 3237 .......NESTED LOOPS (cr=41339 pr=7223 pw=0 time=12.42)
| 3237 ........NESTED LOOPS (cr=38100 pr=7223 pw=0 time=12.39)
| 3237 .........NESTED LOOPS (cr=28296 pr=7139 pw=0 time=12.29)
| 1027 ..........NESTED LOOPS (cr=17656 pr=4471 pw=0 time=3.81)
| 1027 ...........NESTED LOOPS (cr=13537 pr=4404 pw=0 time=3.30)
| 486 ............NESTED LOOPS (cr=10873 pr=4240 pw=0 time=0.04)
| 486 .............NESTED LOOPS (cr=10385 pr=4240 pw=0 time=0.03)
| 486 ..............TABLE ACCESS BY INDEX ROWID RA_CUSTOMER_TRX_ALL (cr=9411 pr=4240 pw=0 time=0.02)
| 75253 ...............INDEX RANGE SCAN RA_CUSTOMER_TRX_N5 (cr=403 pr=285 pw=0 time=0.38)
| 486 ..............TABLE ACCESS BY INDEX ROWID HZ_CUST_ACCOUNTS (cr=974 pr=0 pw=0 time=0.01)
| 486 ...............INDEX UNIQUE SCAN HZ_CUST_ACCOUNTS_U1 (cr=488 pr=0 pw=0 time=0.01)
| 486 .............INDEX UNIQUE SCAN HZ_PARTIES_U1 (cr=488 pr=0 pw=0 time=0.01)
| 1027 ............TABLE ACCESS BY INDEX ROWID RA_CUSTOMER_TRX_LINES_ALL (cr=2664 pr=164 pw=0 time=1.95)
| 2063 .............INDEX RANGE SCAN RA_CUSTOMER_TRX_LINES_N2 (cr=1474 pr=28 pw=0 time=0.22)
| 1027 ...........TABLE ACCESS BY INDEX ROWID RA_CUST_TRX_LINE_GL_DIST_ALL (cr=4119 pr=67 pw=0 time=0.54)
| 1027 ............INDEX RANGE SCAN RA_CUST_TRX_LINE_GL_DIST_N1 (cr=3092 pr=31 pw=0 time=0.20)
| 3237 ..........TABLE ACCESS BY INDEX ROWID MTL_SYSTEM_ITEMS_B (cr=10640 pr=2668 pw=0 time=15.35)
| 3237 ...........INDEX RANGE SCAN MTL_SYSTEM_ITEMS_B_U1 (cr=2062 pr=40 pw=0 time=0.33)
| 3237 .........TABLE ACCESS BY INDEX ROWID OE_ORDER_LINES_ALL (cr=9804 pr=84 pw=0 time=0.77)
| 3237 ..........INDEX UNIQUE SCAN OE_ORDER_LINES_U1 (cr=6476 pr=47 pw=0 time=0.43)
| 3237 ........TABLE ACCESS BY INDEX ROWID MTL_PARAMETERS (cr=3239 pr=0 pw=0 time=0.04)
| 3237 .........INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=2 pr=0 pw=0 time=0.01)
| 741 .......TABLE ACCESS BY INDEX ROWID HR_ORGANIZATION_INFORMATION (cr=6476 pr=0 pw=0 time=0.10)
| 6474 ........INDEX RANGE SCAN HR_ORGANIZATION_INFORMATIO_FK2 (cr=3239 pr=0 pw=0 time=0.03)Please help.
Regards
Ashish| 254644500 ..NESTED LOOPS (cr=519939265 pr=34777 pw=0 time=3819.67)
| 254643758 ...NESTED LOOPS (cr=8921833 pr=29939 pw=0 time=1274.41)There is no way the optimizer should choose to process that many rows using nested loops.
Either the statistics are not up to date, the data values are skewed or you have some optimizer parameter set to none default to force index access.
Please post explain plan and optimizer* parameter settings. -
AR Credit Memo Unit Price Stored Procedure
Dear All,
I am trying to make a SP for A/R Credit Memo wherein the user will not have the option to make the unit price less than the defined price list.
I am using the below SP but its not working and the AR Credit Memo is getting added without any blockage. Please advise
-------------------------------AR Credit Memo Row Price Change-------------------------
IF @OBJECT_TYPE = '14' AND (@TRANSACTION_TYPE = 'A')
BEGIN
IF EXISTS(
SELECT T1.docnum
FROM ORIN T1 Inner join RIN1 T2 on T2.DocEntry = T1.DocEntry
INNER JOIN ITM1 T3 on T3.ItemCode = T2.Itemcode and T3.PriceList = '2'
where t1.docentry = @list_of_cols_val_tab_del
AND T2.Price < T3.Price)
BEGIN
SELECT @ERROR=1,@ERROR_MESSAGE='The price in the line is lesser than the Sales price!'
END
end
Note : I am also using a SP for blocking AR Invoice with unit price change and that SP is working perfectly fine.
IF @OBJECT_TYPE = '13' AND (@TRANSACTION_TYPE = 'A' or @TRANSACTION_TYPE = 'U')
BEGIN
IF EXISTS(
SELECT T1.docnum
FROM OINV T1 Inner join INV1 T2 on T2.DocEntry = T1.DocEntry
INNER JOIN ITM1 T3 on T3.ItemCode = T2.Itemcode and T3.PriceList = '2'
where t1.docentry = @list_of_cols_val_tab_del
AND T2.Price < T3.Price)
BEGIN
SELECT @ERROR=1,@ERROR_MESSAGE='The price in the line is lesser than the Sales price!'
END
end
Kind Regards,
RaviHi,
Tested only your main part query and working as expected.
1. Make sure correct database is selected for above procedures
2. Make sure item tested is same for both invoice and credit memo and same price list.
3. Tested in SQL, there is no problem in blocking AR invoice.
Thanks & Regards,
Nagarajan -
hi Experts,
while running SQL Query i am getting an error as
The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator. for the query
select T1. Dscription,T1.docEntry,T1.Quantity,T1.Price ,
T2.LineText
from OQUT T0 INNER JOIN QUT1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN
QUT10 T2 ON T1.DocEntry = T2.DocEntry where T1.DocEntry='590'
group by T1. Dscription,T1.docEntry,T1.Quantity,T1.Price
,T2.LineText
how to resolve the issueDear Meghanath,
Please use the following query, Hope your purpose will serve.
select T1. Dscription,T1.docEntry,T1.Quantity,T1.Price ,
CAST(T2.LineText as nvarchar (MAX))[LineText]
from OQUT T0 INNER JOIN QUT1 T1 ON T0.DocEntry = T1.DocEntry LEFT OUTER JOIN
QUT10 T2 ON T1.DocEntry = T2.DocEntry --where T1.DocEntry='590'
group by T1. Dscription,T1.docEntry,T1.Quantity,T1.Price
,CAST(T2.LineText as nvarchar (MAX))
Regards,
Amit -
Passing multiple values to a parmeters in SQL Query
Hi friends,
I have the following requirement -
I need to pass multiple values to the parameter 'WHERE hou.name = (:id1)' and the query is copied below for your reference .
SELECT partno part_num,
customer customer_name,
hou.name op_name
FROM hr_organization_units hou,
oe_transaction_types_all sot,
ra_customers rc,
ra_addresses_all ra,
ra_site_uses_all rsu,
oe_order_headers_all h,
oe_order_lines_all l,pwr_sod50 ps
WHERE hou.name = (:id1)
-- and hou.name = (:id4)
--hou.name in ('CPS FRANCE','CPS GERMANY')
--and hou.name = (:id1,hou.name)
and trunc(ps.sch_ship_date) between nvl(:id2,trunc(ps.sch_ship_date)) and nvl(to_date(:id3)+.99999,trunc(ps.sch_ship_date))
and ps.group_id = 9999999
and hou.organization_id=h.org_id
and ps.line_id =l.line_id
and l.header_id =h.header_id
and h.invoice_to_org_id=rsu.site_use_id
and rsu.address_id =ra.address_id
and ra.customer_id =rc.customer_id
and h.order_type_id =sot.transaction_type_id
Looking for your help on this.
Thanks In Advance.
Thanks & Regards
Ramya NomulaHi karthik,
I am sorry for the wrong updation of my anonymus block.
My requirement is to pass a multiple values to the parameter in SQL query, and here is the code which is working now for the multiple values with ourt single quotes to the values -
SELECT partno part_num,
customer customer_name,
ps.customer_id customer_id,
avail_qty avail_qty,
sch_ship_date schedule_Ship_date,
so_num order_no,
h.header_id header_id,
line_num line_no,
l.ordered_quantity ordered_quantity,
scd_qty qty_open,
s_price unit_price,
part_flag flag,
sub_inv subinv,
sbu,
hold,
qoh,
line_detail_id detail_id,
picking_line_id,
picking_line_detail_id,
rc.customer_name cust_name,
rc.customer_number customer_number,
rsu.location location,
sot.attribute5 order_type,
ps.line_id line_id,
h.transactional_curr_code transactional_curr_code,
hou.name op_name
FROM hr_organization_units hou,
oe_transaction_types_all sot,
ra_customers rc,
ra_addresses_all ra,
ra_site_uses_all rsu,
oe_order_headers_all h,
oe_order_lines_all l,pwr_sod50 ps
WHERE ','||:id1||',' like '%,'||hou.name||',%'
and trunc(ps.sch_ship_date) between nvl(:id2,trunc(ps.sch_ship_date)) and nvl(to_date(:id3)+.99999,trunc(ps.sch_ship_date))
and ps.group_id = 9999999
and hou.organization_id=h.org_id
and ps.line_id =l.line_id
and l.header_id =h.header_id
and h.invoice_to_org_id=rsu.site_use_id
and rsu.address_id =ra.address_id
and ra.customer_id =rc.customer_id
and h.order_type_id =sot.transaction_type_id;
Condition for sending multiple Oprtaing Units -
WHERE ','||:id1||',' like '%,'||hou.name||',%'
This above condition is working when i am passing multiple values with out single quotes...but not working for multiple values with single quotes.
Sample queries tested -
select 1 from dual where ',aa,bb,cc,' like '%,bb,%' (This is working)
select 1 from dual where ','aa','bb','cc',' like '%,'bb',%'(This is not working).
Thanks In Advance!
Looking for Your Great Help.
Thanks & Regards
Ramya Nomula -
Value based on the periodic unit price(only with pr.ctrl S) field in MatMas
Dear all,
There is this field in mateial master called "Value based on the periodic unit price (only with pr.ctrl S)" in accounting view 1,
1 - May I know what is this field about (in between our company using material ledger).
2 - May I know why the value of this field are different between our company period 6 and period 7 for this year? what contribute to it? and is it something wrong with different value between two different period or absolutely normal?
Thanks.
TuffHi Tuffy,
For your 1st query:
PUP field in Accounting 1 (if ML is active, Price Determination indicator=3) is the result of Actual Costing Run (CKMLCP) closing entry.
For your 2nd query:
In most of the cases the values will be different in Previous Period and Current Period. e.g.Period 6 values are the results of Actual Costing Run (CKMLCP) in 1st week of Period 6 for Previous Period (i.e. Period 5). Period 7 values are the results of Actual Costing Run (CKMLCP) in 1st week of Period 7 for Previous Period (i.e. Period 6).
The reason for the different values: Price differences, Exchange rate differences, Price/Exchange rate differences from Low lower materials, etc.
Thanks & Regards,
ADI -
Value based on the periodic unit price (only with pr.ctrl S) field in mat.
Dear all,
There is this field in mateial master called "Value based on the periodic unit price (only with pr.ctrl S)" in accounting view 1,
1 - May I know what is this field about (in between our company using material ledger).
2 - May I know why the value of this field are different between our company period 6 and period 7 for this year? what contribute to it? and is it something wrong with different value between two different period or absolutely normal?
Thanks.
TuffHi Tuffy,
For your 1st query:
PUP field in Accounting 1 (if ML is active, Price Determination indicator=3) is the result of Actual Costing Run (CKMLCP) closing entry.
For your 2nd query:
In most of the cases the values will be different in Previous Period and Current Period. e.g.Period 6 values are the results of Actual Costing Run (CKMLCP) in 1st week of Period 6 for Previous Period (i.e. Period 5). Period 7 values are the results of Actual Costing Run (CKMLCP) in 1st week of Period 7 for Previous Period (i.e. Period 6).
The reason for the different values: Price differences, Exchange rate differences, Price/Exchange rate differences from Low lower materials, etc.
Thanks & Regards,
ADI -
Help needed in framing SQL query.
Hi,
I have table having following schema:
PRODUCT_ID INT
DATE DATETIME
ITEMS_SOLD INT
This table contains data for a week (sunday to saturday). I want to write an SQL query to get (filter out) PRODUCT_ID of products which has same no. of ITEMS_SOLD for all 7 days. Also for given PRODUCT_ID I need to find the longest period of successive days where the no. of ITEMS_SOLD is same for all days in this period. Eg.(PRODUCT_ID 23 was sold as following along the week in no. of units sold: 4,6,6,6,6,7,4 .So the longest period is *4 days* from Monday to Thursday.) The first condition is special case of second condition where no. of days is 7.
Any help to get the SQL query will be appreciated.
Thanks,
Akshay.PRODUCT_ID DATE ITEMS_SOLD
1 10/10/2011 3
1 11/10/2011 3
1 12/10/2011 3
1 13/10/2011 3
1 16/10/2011 5
2 10/10/2011 4
2 11/10/2011 4
2 12/10/2011 4
2 13/10/2011 4
2 14/10/2011 4
2 15/10/2011 4
2 16/10/2011 4
Output:
PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
1 3 4
2 4 7
Explanation of results:
The table to be queried contains data for 1 week: from 10/10/2011(Sunday) to 16/10/2011(Saturday). Now, product with PRODUCT_ID '1' was sold on dates 10,11,12,13,16. Out of these 5 days 3 units were sold on 4 successive days (from 10-13). So output should be like :
PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
1 3 4
as longest period of successive days is 4 where same no. of units were sold i.e 3 units (other period is of 1 day on 16th ).
For PRODUCT_ID 2 we have only one period of 7 days where 4 units were sold each day. So we output :
PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
2 4 7
Other case where same PRODUCT_ID have different units sold on each day should be ignored.
I hope that clarifies the problem more. Let me know in case I have missed out anything which should have been mentioned.
-Akshay. -
How do I query off a pl/sql funtion that returns an sql query in apex.
I built a function that a returns a good sql query. I verified the out put of my function works when I manually entered into the SQL Commands.
Is it possible to build a report off of this query. My attempt failed with the following error.
failed to parse SQL query:
ORA-00933: SQL command not properly ended
I am sure the query generated is correct. Like I mentioned, I was able to use in the sql command succesfully.
Thanks,
Edited by: greich on Nov 21, 2008 10:55 AMThis is the code for my function:
create or replace function f_act_proj_sched (i_facility varchar2, i_date varchar2, i_shift varchar2)
Return varchar2 is
o_query Varchar2 (32000);
BEGIN
-- function that will return the query used in main application
o_query := o_query || 'SELECT act_proj.DESTINATION,';
o_query := o_query || ' act_proj.SHIPPING_DATE,';
o_query := o_query || ' act_proj.SHIFT,';
o_query := o_query || ' act_proj.JOB_CLASS_GROUPING,';
o_query := o_query || ' act_proj."Actual Units",';
o_query := o_query || ' act_proj."Projected Units",';
o_query := o_query || ' act_proj."Actual Hours",';
o_query := o_query || ' act_proj."Projected Hours",';
o_query := o_query || ' NVL (sched."Sched_Hours", 0)';
o_query := o_query || ' "Scheduled Hours"';
o_query := o_query || ' From (SELECT P.DESTINATION,';
o_query := o_query || ' P.SHIPPING_DATE,';
o_query := o_query || ' P.JOB_CLASS_GROUPING,';
o_query := o_query || ' P.SHIFT,';
o_query := o_query || ' NVL (FACILITY_STATS.WORK_UNITS, 0) "Actual Units",';
o_query := o_query || ' NVL (P.WORK_UNITS, 0) "Projected Units",';
o_query := o_query || ' NVL (CASE FACILITY_STATS.JOB_CLASS_GROUPING';
o_query := o_query || ' WHEN ''Backhaul''';
o_query := o_query || ' THEN Facility_stats.work_units';
o_query := o_query || ' / Goal_destination_shift.backhauler_goal';
o_query := o_query || ' WHEN ''Selector''';
o_query := o_query || ' THEN Facility_stats.work_units';
o_query := o_query || ' / Goal_destination_shift.selector_goal';
o_query := o_query || ' WHEN ''Common''';
o_query := o_query || ' THEN Facility_stats.work_units';
o_query := o_query || ' / Goal_destination_shift.backhauler_goal';
o_query := o_query || ' WHEN ''Lift''';
o_query := o_query || ' THEN Facility_stats.work_units';
o_query := o_query || ' / Goal_destination_shift.forklift_goal';
o_query := o_query || ' ELSE Facility_stats.work_units';
o_query := o_query || ' END, 0) "Actual Hours",';
o_query := o_query || ' CASE P.JOB_CLASS_GROUPING';
o_query := o_query || ' WHEN ''Backhaul''';
o_query := o_query || ' THEN P.work_units';
o_query := o_query || ' / Goal_destination_shift.backhauler_goal';
o_query := o_query || ' WHEN ''Selector''';
o_query := o_query || ' THEN P.work_units';
o_query := o_query || ' / Goal_destination_shift.selector_goal';
o_query := o_query || ' WHEN ''Common''';
o_query := o_query || ' THEN P.work_units';
o_query := o_query || ' / Goal_destination_shift.backhauler_goal';
o_query := o_query || ' WHEN ''Lift''';
o_query := o_query || ' THEN P.work_units' ;
o_query := o_query || ' / Goal_destination_shift.forklift_goal';
o_query := o_query || ' ELSE P.work_units';
o_query := o_query || ' END "Projected Hours"';
o_query := o_query || ' FROM STAFFING.FACILITY_STATS,';
o_query := o_query || ' STAFFING.FACILITY_STATS P,';
o_query := o_query || ' STAFFING.GOAL_DESTINATION_SHIFT';
o_query := o_query || ' WHERE (GOAL_DESTINATION_SHIFT.DESTINATION = P.DESTINATION)';
o_query := o_query || ' AND (GOAL_DESTINATION_SHIFT.SHIFT_FLAG = P.SHIFT)';
o_query := o_query || ' AND (FACILITY_STATS.DESTINATION(+) = P.DESTINATION)';
o_query := o_query || ' AND (FACILITY_STATS.SHIPPING_DATE(+) = P.SHIPPING_DATE)';
o_query := o_query || ' AND (FACILITY_STATS.JOB_CLASS_GROUPING(+) = P.JOB_CLASS_GROUPING)';
o_query := o_query || ' AND (FACILITY_STATS.SHIFT(+) = P.SHIFT)';
o_query := o_query || ' AND (P.PROJ_ACTUAL_FLAG = ''P'')';
o_query := o_query || ' AND (FACILITY_STATS.PROJ_ACTUAL_FLAG(+) = ''A'')';
o_query := o_query || ' AND P.DESTINATION = ' || i_facility;
o_query := o_query || ' AND P.SHIPPING_DATE = ' || i_date;
o_query := o_query || ' AND (case';
o_query := o_query || ' when to_number(' || i_shift || ') != -1';
o_query := o_query || ' Then P.SHIFT';
o_query := o_query || ' Else 1';
o_query := o_query || ' end =';
o_query := o_query || ' case';
o_query := o_query || ' when to_number(' || i_shift || ') != -1';
o_query := o_query || ' Then to_number(' || i_shift || ')';
o_query := o_query || ' Else 1';
o_query := o_query || ' end)) act_proj,';
o_query := o_query || ' (SELECT Destination,';
o_query := o_query || ' schedule_date,';
o_query := o_query || ' shift,';
o_query := o_query || ' job_class_grouping,';
o_query := o_query || ' SUM ("Sched_Hours") "Sched_Hours"';
o_query := o_query || ' FROM (';
-- Loop to create bucket query
for idx in 1..20 Loop
o_query := o_query || '(SELECT EMP_SCHEDULE.EMPLOYEE_ID,';
o_query := o_query || ' EMP_SCHEDULE.SCHEDULE_DATE,';
o_query := o_query || ' EMP_SCHEDULE.DESTINATION,';
o_query := o_query || ' EMP_SCHEDULE.SHIFT, ';
o_query := o_query || idx || ' "Bucket_number",';
o_query := o_query || ' Bucket' || idx || '_class "bucket class",';
o_query := o_query || ' JOB_CLASS_GROUPING,';
o_query := o_query || ' NVL (EMP_SCHEDULE.BUCKET' || idx || '_SCHED_HRS, 0) "Sched_Hours"';
o_query := o_query || ' FROM STAFFING.EMP_SCHEDULE,';
o_query := o_query || '(SELECT DISTINCT FACILITY_CLASS_BUCKET.JOB_CLASS_GROUPING,';
o_query := o_query || ' FACILITY_CLASS_BUCKET.DESTINATION';
o_query := o_query || ' FROM STAFFING.FACILITY_CLASS_BUCKET';
o_query := o_query || ' WHERE (FACILITY_CLASS_BUCKET.BUCKET_ID = ' || idx || ')) A';
o_query := o_query || ' Where A.Destination = EMP_SCHEDULE.DESTINATION';
o_query := o_query || ' and EMP_SCHEDULE.DESTINATION = ' || i_facility;
o_query := o_query || ' and EMP_SCHEDULE.SCHEDULE_DATE = ' || i_date;
o_query := o_query || ' AND (case';
o_query := o_query || ' when to_number(' || i_shift || ') != -1';
o_query := o_query || ' Then EMP_SCHEDULE.SHIFT';
o_query := o_query || ' Else 1';
o_query := o_query || ' end =';
o_query := o_query || ' case';
o_query := o_query || ' when to_number(' || i_shift || ') != -1';
o_query := o_query || ' Then to_number(' || i_shift || ')';
o_query := o_query || ' Else 1';
o_query := o_query || ' end))';
if idx < 20
THEN
o_query := o_query || ' UNION ';
Else
o_query := o_query || ')';
End if;
END Loop;
o_query := o_query || ' GROUP BY Destination,';
o_query := o_query || ' schedule_date,';
o_query := o_query || ' shift,';
o_query := o_query || ' job_class_grouping) Sched';
o_query := o_query || ' WHERE (act_proj.DESTINATION = sched.DESTINATION(+))';
o_query := o_query || ' AND (act_proj.SHIPPING_DATE = sched.SCHEDULE_DATE(+))';
o_query := o_query || ' AND (act_proj.SHIFT = sched.SHIFT(+))';
o_query := o_query || ' AND (act_proj.JOB_CLASS_GROUPING = sched.JOB_CLASS_GROUPING(+))';
o_query := o_query || ' ORDER BY SHIFT,';
o_query := o_query || ' job_class_grouping';
Return (o_query);
END;
Maybe you are looking for
-
Process: Safari [512] Path: /Applications/Safari.app/Contents/MacOS/Safari Identifier: com.apple.Safari Version: 8.0.2 (10600.2.5) Build Info: WebBrowser-7600002005000000~1 Code Type:
-
Ok I am new to this and have never setup a home server or installed oracle. I have however used oracle extensively and know a lot about it. I am using php I have done the following I am using oracle 11g wamp server and I think i have the ori8 working
-
My iMessage is not properly working and I need help.Just look at the question and give me a response. thanks.
-
IOS 7 on iPad mini is sooooo SLOW!
All the built-in apps lags and crash sometimes. I can't watch videos or play my games without waiting for more than 3 secs to open or some buttons are not working well. Do you guys experience this too? Please help, Apple guys! After all you pr
-
Error using google from dashboard
I loaded the google basic search app on my dashboard and I'm getting an error from google saying this IP address is not authorized to use this....anybody else have this issue????