Hi All
I have one table where I have:
1) part number
2) location
3) Vendor ID
and I have another table where I have additional info - list price and buy price (which sometimes is not added in error)
1) part number
2) location
3) category: list price OR buy price
4) value
-- unfortuanately I don't have Vendor ID in this table
so I have several rows for the same number and location (list price and buy price)
I need to show
1) Vendor ID
2) unique number
3) location
4) value (list price) - if added
5) value (buy price) - if added
I tried to use self join but it is not showing me all the records, I tried to use subquery but I'm not too good with subqueries ;)
Many thanks in advance
Emil
7 1341
Here is what I used however it is not showing me records where UP or/and UC is missing (see below) - Any suggestions?
SET TRANSACTION ISOLATION LEVEL
READ UNCOMMITTED
BEGIN TRANSACTION
SELECT e1.number, e1.location, cast(e1.cost/10000 AS DECIMAL(12,2)) AS UP , CAST(e2.cost/10000 AS DECIMAL(12,2)) AS UC
FROM TblLocation as e1 FULL OUTER JOIN TblLocation as e2 ON e1.number+e1.location = e2.number+e2.location
FULL OUTER JOIN tblMaster ON RTRIM(MasterNumber)+RTRIM(MasterLocation) = RTRIM(e2.number)+RTRIM(e2.location)
WHERE e1.category = 'UP' and e2.category = 'UC' and VendorID = 'XXX'
COMMIT TRANSACTION
ck9663 2,878
Recognized Expert Specialist
Hi All
I have one table where I have:
1) part number
2) location
3) Vendor ID
and I have another table where I have additional info - list price and buy price (which sometimes is not added in error)
1) part number
2) location
3) category: list price OR buy price
4) value
-- unfortuanately I don't have Vendor ID in this table
so I have several rows for the same number and location (list price and buy price)
I need to show
1) Vendor ID
2) unique number
3) location
4) value (list price) - if added
5) value (buy price) - if added
I tried to use self join but it is not showing me all the records, I tried to use subquery but I'm not too good with subqueries ;)
Many thanks in advance
Emil
Is PartNumber and Location enough for you to use as join key even without VendorID?
-- CK
combination of part number and location in the first table is unique
ck9663 2,878
Recognized Expert Specialist
From which table the Cost column came from?
-- CK
From the second the table --4) value--
ck9663 2,878
Recognized Expert Specialist
I'm a little confuse. Your desired output include these:
4) value (list price) - if added
5) value (buy price) - if added
How would you know if they are list price or buy price? Can you just post some sample data and your desired output? Include some partnumber that are not in table2 and how you want to handle it.
-- CK
Delerna 1,134
Recognized Expert Top Contributor
is something like this what you are after -
SELECT PartNumber,Location,VendorID,sum(UP) as UP,sum(UC) as UC
-
FROM
-
( SELECT a.PartNumber,a.Location,a.VendorID,
-
case when b.category='UP' then Value else 0 end as UP,
-
case when b.category='UC' then Value else 0 end as UC
-
FROM tblMaster a
-
LEFT JOIN tblLocation b on a.partnumber=b.partnumber
-
and a.location=b.location
-
WHERE VendorID='XXX'
-
) c
-
GROUP BY PartNumber,Location
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: StealthBananaT |
last post by:
My database has two tables - films has 10,000 records and reviews has 20,000 records. Whenever I try to list all the films and the
count of its reviews, MySQL locks and I have to restart the...
|
by: Soefara |
last post by:
Dear Sirs,
I am experiencing strange results when trying to optimize a LEFT JOIN
on 3 tables using MySQL.
Given 3 tables A, B, C such as the following:
create table A (
uniqueId int not...
|
by: Martin |
last post by:
I am now working on SQL Server 2000 having had previous experience on
a different database. Both of the OUTER JOIN syntaxes is different
from what I am used to and I am finding it slightly...
|
by: Matt |
last post by:
Hello
I have to tables ar and arb, ar holds articles and a swedish
description, arb holds descriptions in other languages.
I want to retreive all articles that match a criteria from ar and...
|
by: Gene Ariani |
last post by:
I have one dataset that contains two DataTables:
DataTable1:
Customer_ID
1
| |
by: don |
last post by:
I have written a program to hold a sales contact db. It is written in c#
express.
an update is sent from head office in xl format, i need to import only the
new rows to an access database.
I...
|
by: Dot Net Daddy |
last post by:
Hello,
I have set up a database for movies. In one table (Movies) I have
movie names, and production years, and also genres. In another table
(Directors), I keep the directors and the movies...
|
by: Zeff |
last post by:
Hi all,
I have a relational database, where all info is kept in separate tables
and just the id's from those tables are stored in one central table
(tblMaster)...
I want to perform a query, so...
|
by: prn |
last post by:
Hi Folks,
Sorry if I have the forum wrong, It's more a SQL question than a SQL Server question, but it is intended to run on MS SQL Server at least. :)
I'm trying to construct a query and am...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |