Vendors With a PO
Last Modified on 18/07/2017 4:15 pm EDT
SELECT v.VendorName AS Company,
Vemail AS [Email],
v.CellAreaCode AS [Cell Area Code],
v.CellDigits [Cell],
p.AreaCode AS [Phone1 Area Code],
p.Digits AS [Phone1],
p2.AreaCode AS [Phone2 Area Code],
p2.Digits AS [Phone2],
(SELECT TOP(1) OrderDate
FROM tblPo
WHERE Archaived = 'N'
AND VendorCode = PVendorCode
ORDER BY OrderDate DESC) AS [Last Order Date]
FROM tblvendor v
LEFT OUTER JOIN tblphones p ON v.Phone1ID = p.id
LEFT OUTER JOIN tblphones P2 ON v.Phone2ID = P2.id
WHERE (v.Disabled <> 'true')
AND v.VendorCode IN
(SELECT DISTINCT PVendorCode
FROM tblPo
WHERE Archaived = 'N')