I have 3 table for Purchase Order from ERP Database
Tables:
POD=Purchase order Details(this table has Require Qty field)
POR=Purchase Order Receive (This table has RequireQty and ReceiptQty Fields)
POI=Purchase order Inspect
I want a query to display Purchase order History. My Query is here - SELECT dbo.POD.POD_PurchOrderID, dbo.POD.POD_POLineNbr, dbo.POI.POI_StatusCode,
-
dbo.ProjectGroup.PRJG_ProjectID, dbo.POI.POI_Reference, dbo.POI.POI_ItemName,
-
dbo.POI.POI_UnitMeasure, dbo.POD.POD_RequiredDate, dbo.POD.POD_PromiseDate,
-
dbo.POR.POR_ReceiverDate, dbo.POD.POD_RequiredQty, dbo.POR.POR_ReceiptQty, dbo.POD.POD_POUnitPrice,
-
dbo.POD.POD_POUnitPrice * dbo.POR.POR_ReceiptQty AS Amt
-
FROM dbo.POD INNER JOIN
-
dbo.POR ON dbo.POD.POD_RequiredDate = dbo.POR.POR_RequiredDate AND
-
dbo.POD.POD_PurchOrderID = dbo.POR.POR_PurchOrderID INNER JOIN
-
dbo.POI ON dbo.POD.POD_POLineNbr = dbo.POI.POI_POLineNbr AND
-
dbo.POR.POR_POLineNbr = dbo.POI.POI_POLineNbr AND
-
dbo.POD.POD_PurchOrderID = dbo.POI.POI_PurchOrderID INNER JOIN
-
dbo.ProjectGroup ON
-
dbo.POD.POD_PRJG_RecordID = dbo.ProjectGroup.PRJG_RecordID
This query only displaying the records which i have received and inspect. But still i have some records thats not received and inspect.
I want to display all the records which is received and not recieved
If not received receipt qty field should be null.
ERP generate records according porecipt. If not receipt then no records in POR table
Thnx
7 1793
It's because you're using INNER JOIN.
Try using LEFT or RIGHT JOIN.
-- CK
It's because you're using INNER JOIN.
Try using LEFT or RIGHT JOIN.
-- CK
If i use right join i m getting the same result. but left join producing duplicate records.
Example result:
Now i m getting the report like this(This is Example displaying only few fields) PurchOrderID,POLineNbr,ProjectID,....,RequiredQty, ReceiptQty ,.........
PO12345, 1, S01243, ....,45.00, 25.00, ..........
PO12345, 1, S01234, .....,10.00, 10.00,...........
PO12345, 2, S01234, .....,25.00, 25.00 ..........
But i want the result like This PurchOrderID,POLineNbr,ProjectID,....,RequiredQty, ReceiptQty ,.........
PO12345, 1, S01243, ....,45.00, 25.00, ..........
PO12345, 1, S01234, .....,10.00, 10.00,...........
PO12345, 2, S01234, .....,25.00, 25.00 ..........
PO12345, 3, S01233, ......,15.00, 0.00, ...........
In this above example the POLineNbr 3 (result row 4) still not yet received. So i dont records exist POR Table. But i want to display those records in my report.
Please give me the query or example site to get this
Thanks
SELECT dbo.POD.POD_PurchOrderID, dbo.POD.POD_POLineNbr, dbo.POI.POI_StatusCode,
dbo.ProjectGroup.PRJG_ProjectID, dbo.POI.POI_Reference, dbo.POI.POI_ItemName,
dbo.POI.POI_UnitMeasure, dbo.POD.POD_RequiredDate, dbo.POD.POD_PromiseDate,
dbo.POR.POR_ReceiverDate, dbo.POD.POD_RequiredQty, dbo.POR.POR_ReceiptQty, dbo.POD.POD_POUnitPrice,
dbo.POD.POD_POUnitPrice * dbo.POR.POR_ReceiptQty AS Amt
FROM dbo.POD
--- In SQL the Table follow FROM clause is considered as LEFT Table
-- The Table which follow the JOIN stmt are considered as RIGHT Table
INNER JOIN
dbo.POR ON dbo.POD.POD_RequiredDate = dbo.POR.POR_RequiredDate AND
dbo.POD.POD_PurchOrderID = dbo.POR.POR_PurchOrderID INNER JOIN
dbo.POI ON dbo.POD.POD_POLineNbr = dbo.POI.POI_POLineNbr AND
dbo.POR.POR_POLineNbr = dbo.POI.POI_POLineNbr AND
dbo.POD.POD_PurchOrderID = dbo.POI.POI_PurchOrderID INNER JOIN
dbo.ProjectGroup ON
dbo.POD.POD_PRJG_RecordID = dbo.ProjectGroup.PRJG_RecordID
-------------------------------------------------------------------------------------------------------
In SQL the Table follow FROM clause is considered as LEFT Table
The Table which follow the JOIN stmt are considered as RIGHT Table
Based on the above information u can try...
Ganesh
SELECT dbo.POD.POD_PurchOrderID, dbo.POD.POD_POLineNbr, dbo.POI.POI_StatusCode,
dbo.ProjectGroup.PRJG_ProjectID, dbo.POI.POI_Reference, dbo.POI.POI_ItemName,
dbo.POI.POI_UnitMeasure, dbo.POD.POD_RequiredDate, dbo.POD.POD_PromiseDate,
dbo.POR.POR_ReceiverDate, dbo.POD.POD_RequiredQty, dbo.POR.POR_ReceiptQty, dbo.POD.POD_POUnitPrice,
dbo.POD.POD_POUnitPrice * dbo.POR.POR_ReceiptQty AS Amt
FROM dbo.POD
--- In SQL the Table follow FROM clause is considered as LEFT Table
-- The Table which follow the JOIN stmt are considered as RIGHT Table
INNER JOIN
dbo.POR ON dbo.POD.POD_RequiredDate = dbo.POR.POR_RequiredDate AND
dbo.POD.POD_PurchOrderID = dbo.POR.POR_PurchOrderID INNER JOIN
dbo.POI ON dbo.POD.POD_POLineNbr = dbo.POI.POI_POLineNbr AND
dbo.POR.POR_POLineNbr = dbo.POI.POI_POLineNbr AND
dbo.POD.POD_PurchOrderID = dbo.POI.POI_PurchOrderID INNER JOIN
dbo.ProjectGroup ON
dbo.POD.POD_PRJG_RecordID = dbo.ProjectGroup.PRJG_RecordID
-------------------------------------------------------------------------------------------------------
In SQL the Table follow FROM clause is considered as LEFT Table
The Table which follow the JOIN stmt are considered as RIGHT Table
Based on the above information u can try...
Ganesh
Hi Ganesh,
Sorry it has taken me a while to get back to you, but thanks very much for your sql
Imthi
But Still i didnt get what i want. I have three table (POD-PoDetails, POR-PoRecieve & POI-PoInspect)
POD is base table for the rest. In the POR & POI the records only generated if the Item received/Inspect Respectively. Also both POR&POI operation not done in same time some times they will take upto one week. Untill then the record not exist in the respective table.
My query fields link with all this 3 tables if the record is not exist even in one table the records it wont display. Its basic i know.
But i need the recorsd to display. if the field is not exist then it should show NULL value.
Thanks
Try this -
SELECT POD.POD_PurchOrderID,
-
POD.POD_POLineNbr,
-
POI.POI_StatusCode,
-
ProjectGroup.PRJG_ProjectID,
-
POI.POI_Reference,
-
POI.POI_ItemName,
-
POI.POI_UnitMeasure,
-
POD.POD_RequiredDate,
-
POD.POD_PromiseDate,
-
POR.POR_ReceiverDate,
-
POD.POD_RequiredQty,
-
POR.POR_ReceiptQty,
-
POD.POD_POUnitPrice,
-
POD.POD_POUnitPrice * dbo.POR.POR_ReceiptQty AS Amt
-
FROM dbo.POD
-
LEFT JOIN POR ON POD.POD_PurchOrderID = POR.POR_PurchOrderID
-
LEFT JOIN POI ON POD.POD_PurchOrderID = POI.POI_PurchOrderID
-
AND POR.POR_POLineNbr = POI.POI_POLineNbr
-
LEFT JOIN ProjectGroup ON POD.POD_PRJG_RecordID = ProjectGroup.PRJG_RecordID
-
If that dosn't work then post all the field names in all of the involved tables and maybe some demo data along with it and I will give you one that does.
It is not absolutely clear on what the necessary fields to join to are because you only list a few, and some of the crucial ones are missing.
I don't know why you joined to the RequiredDate so I removed it. I felt it might be unnecessary.
Anyway, hopefully the above will work for you. If not post what I requested
Thnx for ur support. Its Ok now
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jack |
last post by:
Hi,
I have posted this problem before. Apprently, the suggestion took care of
the problem. However, still I am getting the above error message.
I am using a session variable to transfer a value...
|
by: middletree |
last post by:
I've been messing with this for hours, and have been to various sites,
including Aaron's site, and am truly stumped.
The short version: in SQL Server, the 4 fields in question are datetime. I...
|
by: Laurel |
last post by:
this is driving me crazy. i need to use a form control as a criteria
in a select query, and the control's value is set depending upon what
a user selects in an option group on the form. the query...
|
by: Peter Phelps |
last post by:
My problem is as follows:
I need automatically iterate through a single field in a table and use
the values in the field to create an in-statement. Currently, the
character limitation in the...
|
by: Martin Lacoste |
last post by:
Is there some issue with using too many left/right/mid/len functions
in queries? Depending on the usage, they work fine, but... then
there's here:
SELECT Master_CAO.Incipit,...
|
by: martlaco1 |
last post by:
Trying to fix a query that (I thought) had worked once upon a time, and
I keep getting a Data Type Mismatch error whenever I enter any criteria
for an expression using a Mid function. Without the...
|
by: Mike |
last post by:
Type Mismatch error
I recieve a type mismatch error on the following line of code which is
based on a specific date. It does NOT break on all records only
"some". The dates for the records...
|
by: zz12 |
last post by:
Hello, is there a setting in IIS 5.0 that would quickly fix the following
error?:
Microsoft VBScript runtime (0x800A000D)
Type mismatch
It's strange because some of our .asp pages were...
|
by: rscheinberg |
last post by:
I am working in Access 2007 attempting to grab 2 characters from a text field named ProjectNumber. After determining what 2 digits to add in front to make it a year, I need to do that. I have done...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |