SELECT DISTINCT licenseagreement.agreementnumber "Agreement Number",
softwaremanufacturer.NAME "Manufacturer",
Longtodate(licenseagreement.acquisitiondate) "Acquisition Date",
Longtodate(licenseagreement.expirydate) "Expiry Date",
CASE
WHEN licenseagreement.expirydate = 0 THEN NULL
ELSE
( ( licenseagreement.expirydate / 1000 ) -
Datediff(s, '19700101', Getdate()) ) / 60 / 60 / 24
END "ExpireIn",
licenseagreement.pocustomid "PO No:",
agreementstatus.statusname "Status" FROM licenseagreement
LEFT JOIN agreementstatus
ON licenseagreement.statusid = agreementstatus.statusid
LEFT JOIN softwaremanufacturer
ON licenseagreement.swmanufacturerid =
softwaremanufacturer.swmanufacturerid