List items on the Purchase Order Grid based on the selection criteria in the 'Where' clause bolded below
SELECT P.Location,
P.ID,
P.PVendorCode,
ISNULL(B.RDate, 'Jan 1 1980') AS rdate,
(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) AS CustomerName,
(CASE P.CrossRental
WHEN 'Y' THEN (CASE B.ShowStartTime
WHEN 'VEND' THEN V.VCurrency
ELSE C.CurrencyStr
END)
ELSE V.VCurrency
END) AS CurrencyStr,
ISNULL(ActualPOCurrency, '') AS ActualPOCurrency,
P.MonthYearFilter,
P.OrderDate,
P.PPONumber,
P.PtotalAmount,
P.Approved,
(CASE P.CrossRental
WHEN 'Y' THEN 'Y'
ELSE P.PPostedToOnOrd
END) AS Posted,
P.PReceived,
P.ProjectCode,
P.Archaived,
P.OrderedBy,
P.CrossRental,
P.ExpectedDate,
(CASE P.CrossRental
WHEN 'Y' THEN B.Assigned_To_V61
ELSE P.POBooking_No
END) AS BookingNo,
P.InvoiceStatus,
P.AirBill,
P.Description,
V.MinPOAmount,
(CASE P.CrossRental
WHEN 'Y' THEN B.Booking_No
ELSE ''
END) AS RealBookingNo,
d.div_name AS Division
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 tblDivlist d ON d.div_number = B.Division
WHERE LEN(P.PVendorCode) > 0
AND P.Location = 0
AND P.Archaived = 'N'
AND B.Division = 0
AND P.InvoiceStatus = 0
ORDER BY P.PPONumber