Purchase Orders for the last 90 Days
Last Modified on 20/11/2017 10:45 am EST
SELECT p.location,
P.PVendorCode [Vendor Code],
(CASE P.CrossRental
WHEN 'Y' THEN (CASE
WHEN B.ShowStartTime = 'CUST'
AND LEN(C.OrganisationV6) > 0 THEN C.OrganisationV6
ELSE V.VendorName
END)
ELSE V.VendorName
END) [Vendor Name],
P.OrderDate [Date Ordered],
P.ExpectedDate [Date Required],
ISNULL(B.RDate, 'Jan 1 1980') [Return Date (CR Only)],
P.PPONumber [PO Number],
P.PtotalAmount [PO Total Amount],
(CASE P.Approved
WHEN 0 THEN 'N'
ELSE 'Y'
END) [Approved],
(CASE P.CrossRental
WHEN 'Y' THEN 'Y'
ELSE P.PPostedToOnOrd
END) [Posted],
P.PReceived [Received],
P.ProjectCode [Project Code],
P.OrderedBy [Ordered By],
p.RequestedBy[Requested BY],
(CASE P.CrossRental
WHEN 'Y' THEN R.Salesperson
ELSE ISNULL(B.Salesperson,'')
END) [SalesPerson],
P.CrossRental [Cross Rental],
(CASE P.CrossRental
WHEN 'Y' THEN B.Assigned_To_V61
ELSE P.POBooking_No
END) [Assigned to Booking],
P.InvoiceStatus [Invoice Status],
P.Description,
V.MinPOAmount [Min PO Amount],
(CASE P.CrossRental
WHEN 'Y' THEN B.Booking_No
ELSE ''
END) [Cross
Rental Booking No]
FROM tblPO P
LEFT OUTER JOIN tblVendor V ON P.PVendorCode = V.VendorCode
LEFT OUTER JOIN tblCust C ON C.Customer_Code = P.PVendorCode
LEFT OUTER JOIN tblBookings B ON P.POBooking_no = B.booking_no
LEFT OUTER JOIN tblBookings R ON B.Assigned_To_V61 = R.booking_no
WHERE P.OrderDate >= cast((GETDATE() -90) AS date)
ORDER BY p.location,
P.PPONumber DESC