T-SQL – replace TOP 1 field with MAX(field) to gain speed, cure errors
Say, you need to get a single top order number from a related table. You might use this TOP 1 syntax: , ISNULL((SELECT TOP 1 D1.CDDOCO FROM CRPDTA.F1721 D1 WHERE D1.CDNUMB = FANUMB AND D1.CDCDTE > @TODAY ORDER BY D1.CDDOCO DESC), ”) [Top contract] However, if your output returns over […]