?
Solved

SQL query in SAP Business One

Posted on 2014-11-12
2
Medium Priority
?
184 Views
Last Modified: 2015-10-15
Hi Experts,

I have a problem with a SQL query I am trying to create in my SAP Business One application.

What I want to show is ALL the products in my DB which begin with the code 'COV', the amount we have in stock, how many are committed, how many are expected where we have stock on Purchase Order.   I have 116 products in the DB which start  with COV so in my query result set I always expect to see 116 results.  

I am taking the delivery from from the t2.shipdate column  which is at row level in Purchase Orders.   I only want to show a delivery date if we are expecting stock (t0.onorder >0) and there is a delivery date in the future.  

If there is stock on order then I want to show the nearest ship date in the future.  

I have attached the layout of the result set and the query which produced it.   Please see example of Product COV004-16

It is returning expected delivery date of 16.09.2014 but that is from a previous delivery which has already been recived into stock.   The nearest expected date is actually 09.02.2015 so it appears to be returning a date from a PO which as already been delivered.

The other problem is that I am not seeing all 116 COV products.   Some part of my query is filtering them down to 106


This is the query I have so far:

SELECT T0.[ItemCode], T0.[ItemName], T0.[OnHand]'Physical_Stock', T0.[IsCommited]'On_Sales_Order', T0.[OnOrder]'On_Purchase_Order',

                                CASE WHEN t0.onorder=0 THEN null ELSE max(T2.[ShipDate])

end as 'Expected_Delivery',SUM(T1.[Quantity])'Invoiced_Qty_12_months'

FROM OITM T0 LEFT JOIN INV1 T1 ON T0.ItemCode = T1.ItemCode LEFT JOIN POR1 T2 ON T0.ItemCode = T2.ItemCode

WHERE T0.[ItemCode]  like 'COV%' and T2.shipdate < ( select max(T2.shipdate) from POR1 t2 where T2.[ItemCode]  like 'COV%' )

GROUP BY T0.[ItemCode], T0.[ItemName], T0.[OnHand], T0.[IsCommited], T0.[OnOrder]
0
Comment
Question by:JonYen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Accepted Solution

by:
Vsevolod Geraskin earned 1000 total points
ID: 40438751
Hard to tell without seeing a table structure, but the following part will filter out all rows with the latest shipdates from t2.

T2.shipdate < ( select max(T2.shipdate) from POR1 t2 where T2.[ItemCode]  like 'COV%' )

Open in new window

0
 
LVL 51

Assisted Solution

by:Vitor Montalvão
Vitor Montalvão earned 1000 total points
ID: 40439700
I have attached the layout of the result set and the query which produced it.   Please see example of Product COV004-16
Did you? Where?
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question