SELECT productType.COMPONENTTYPENAME AS "Product Type", resource.RESOURCENAME AS "Asset Name1", resource.RESOURCENAME AS "Asset Name", product.COMPONENTNAME AS "Product",
LONGTODATE(resource.ACQUISITIONDATE) AS "Acquisition Date", aaov.NAME AS "Site", resToCost.PURCHASECOST AS "Purchase Cost",
resToCost.TOTALCOST AS "Total Cost", resToCost.CURRENTCOST AS "Current Book Value", state.DISPLAYSTATE AS "Asset State",
to_char(to_timestamp(to_char((dep.MONTH+1), '999'), 'MM'), 'Mon') "Months", dep.YEAR "Year", dep.bookvalue "Book Value on Depreciation" FROM Resources resource
LEFT JOIN ComponentDefinition product ON resource.COMPONENTID=product.COMPONENTID
LEFT JOIN ComponentType productType ON product.COMPONENTTYPEID=productType.COMPONENTTYPEID
LEFT JOIN ResourceState state ON resource.RESOURCESTATEID=state.RESOURCESTATEID
LEFT JOIN ResourceLocation resLocation ON resource.RESOURCEID=resLocation.RESOURCEID
LEFT JOIN SiteDefinition siteDef ON resLocation.SITEID=siteDef.SITEID
LEFT JOIN SDOrganization aaov ON siteDef.SITEID=aaov.ORG_ID
LEFT JOIN ResourceToCost resToCost ON resource.RESOURCEID=resToCost.RESOURCEID
LEFT JOIN ResourceDepreciationValue dep on resource.RESOURCEID = dep.RESOURCEID
and ( (dep.YEAR = date_part('year', timestamp '2018-02-28') and dep.MONTH >= (date_part('month', timestamp '2018-02-28'))-1) OR dep.YEAR > date_part('year', timestamp '2018-02-28'))
and ( (dep.YEAR = date_part('year', timestamp '2019-02-28') and dep.MONTH <= (date_part('month', timestamp '2021-02-28'))-1) OR dep.YEAR < date_part('year', timestamp '2021-03-28')) ORDER BY 2, dep.DEPRECIATIONVALUEID
MSSQL:
SELECT productType.COMPONENTTYPENAME AS "Product Type", resource.RESOURCENAME AS "Asset Name1", resource.RESOURCENAME AS "Asset Name", product.COMPONENTNAME AS "Product",
LONGTODATE(resource.ACQUISITIONDATE) AS "Acquisition Date", aaov.NAME AS "Site", resToCost.PURCHASECOST AS "Purchase Cost",
resToCost.TOTALCOST AS "Total Cost", resToCost.CURRENTCOST AS "Current Book Value", state.DISPLAYSTATE AS "Asset State" FROM Resources resource
LEFT JOIN ComponentDefinition product ON resource.COMPONENTID=product.COMPONENTID
LEFT JOIN ComponentType productType ON product.COMPONENTTYPEID=productType.COMPONENTTYPEID
LEFT JOIN ResourceState state ON resource.RESOURCESTATEID=state.RESOURCESTATEID
LEFT JOIN ResourceLocation resLocation ON resource.RESOURCEID=resLocation.RESOURCEID
LEFT JOIN SiteDefinition siteDef ON resLocation.SITEID=siteDef.SITEID
LEFT JOIN SDOrganization aaov ON siteDef.SITEID=aaov.ORG_ID
LEFT JOIN ResourceToCost resToCost ON resource.RESOURCEID=resToCost.RESOURCEID
ORDER BY 2