• Ninja's_RGR'us (11/21/2011)


    I know it depends, but I'm getting sick of making that argument so I was hoping one of you guys would take care ot that! 😉

    I'll never tire of repeating this, until (hopefully) some day I don't have to do it anymore.

    So here goes - without ORDER BY, there is no way to predict which of the five rows will be the TOP 1 row; answer options 1 and 2 are both correct (and there are lots of other correct answer options as well).

    The explanation is also partially misleading.

    "But if your replace the "SELECT TOP 1 t1 FROM @table" with "SET @ReorderPoint= (SELECT TOP 1 t1 FROM @table)", it give error message like "Error converting data type varchar to int.". "

    Well - it may do that. But if the row that happens to be returned by the TOP 1 without ORDER BY is one of the rows with t1 equal to 145.87, 1059.31, or 38.49, it will happily convert taht value from varchar to int (or decimal, or float).

    Finally, the "TOP 1" syntax is still supported, but Microsoft recommends against using it. In the officianl syntax, parentheses are required: "TOP (1)".

    See http://msdn.microsoft.com/en-us/library/ms189463.aspx


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/