I am in an intro to database class and am having trouble with my query. I am trying to return the information that would be generated for a PurchaseOrderHeader. I cannot get it to return anything.
Use [Sandwiches Inc]
GO
DECLARE
@VendorID INT,
@TodaysDate DATETIME,
SELECT @VendorID = 3,
@TodaysDate = GETDATE();
SELECT
@VendorID AS Vendor,
@TodaysDate AS TDate,
V.Name,
V.Phone,
A2.Address1,
A2.Address2,
A2.AdressState,
A2.City,
A2.Zip,
A1.Address1,
A1.Address2,
A1.AdressState,
A1.City,
A1.Zip
FROM Vendor AS V
INNER JOIN VendorAddress AS VA1 on V.VendorId = VA1.VendorId
--INNER JOIN VendorAddress AS VA2 on V.VendorId = VA2.VendorId
INNER JOIN VdrAddress as A1 on VA1.VdrAddressId = A1.VdrAddressId
INNER JOIN VdrAddress AS A2 on VA1.VdrAddressId = A2.VdrAddressId
WHERE A1.Name = 'Billing' And A2.Name = 'Shipping' And V.VendorId = 3
GO
As it is now, it executes but does not return any columns. If I only do A1 or A2 and comment out one or the other, it works. It is when I try to do both that it fails.
Any help would be appreciated. If you need more information I can elaborate.
I don’t suppose you removed the WHERE constraints to see if there is actually nothing in the greater result set?
I also assume there is relevant data in all the tables?
Where I would go from here is to remove all but one join, then slowly re-add them so I can narrow down where the issue lays.
Try that, and come back to us with more specifics.
(Ps. this is hard to do when we have no idea what is in the tables)