select TOP (all)

前端 未结 8 2071
再見小時候
再見小時候 2020-12-15 16:46
declare @t int
set @t = 10
if (o = \'mmm\') set @t = -1
select top(@t) * from table

What if I want generally it resulted with 10 rows, but rarely a

8条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-15 17:28

    Use the statement "SET ROWCOUNT @recordCount" at the beginning of the result query.The variable "@recordCount" can be any positive integer. It should be 0 to return all records.

    that means , "SET ROWCOUNT 0" will return all records and "SET ROWCOUNT 15" will return only the TOP 15 rows of result set.

    Drawback can be the Performance hit when dealing with large number of records. Also the SET ROWCOUNT will be effective throughout the scope of execution of the whole query.

提交回复
热议问题