SQL Select 'n' records without a Table

前端 未结 8 577
隐瞒了意图╮
隐瞒了意图╮ 2020-12-30 03:33

Is there a way of selecting a specific number of rows without creating a table. e.g. if i use the following:

SELECT 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
         


        
8条回答
  •  悲哀的现实
    2020-12-30 03:50

    Using PIVOT (for some cases it would be overkill)

    DECLARE @Items TABLE(a int, b int, c int, d int, e int); 
    
    INSERT INTO @Items
    VALUES(1, 2, 3, 4, 5)
    
    SELECT Items 
    FROM @Items as p 
    UNPIVOT     
    (Items FOR Seq IN          
    ([a], [b], [c], [d], [e]) ) AS unpvt 
    

提交回复
热议问题