1) CAST(... AS VARCHAR) returns only first character. CONVERT(VARCHAR, ...) returns all characters.
2) There is no ORDER BY, so the TOP 1 cannot be guaranteed.
3) This is more efficient
select Top 1 dateadd(month, 12 * prdYear - 22801 + prdMonth, 0) from AgentProductionReport
order by prdYear DESC, prdMonth DESC
select dateadd(month, 12 * prdYear - 22801 + prdMonth, 0) from AgentProductionReport
order by prdYear DESC, prdMonth DESC
|