How can I select from list of values in SQL Server

后端 未结 14 1858
隐瞒了意图╮
隐瞒了意图╮ 2020-11-28 18:08

I have very simple problem that I can\'t solve. I need to do something like this:

select distinct * from (1, 1, 1, 2, 5, 1, 6).

Anybody can

14条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 18:37

    A technique that has worked for me is to query a table that you know has a large amount of records in it, including just the Row_Number field in your result

    Select Top 10000 Row_Number() OVER (Order by fieldintable) As 'recnum' From largetable
    

    will return a result set of 10000 records from 1 to 10000, use this within another query to give you the desired results

提交回复
热议问题