sql server - How to get a fixed number of rows in sql -
if have 4 rows in database these.
|____a____|____b_____| | a1 | b1 | | a2 | b2 | | a3 | b3 | | a4 | b4 |
but need display 10 rows added no
column serial number each row these
__no__|____a____|____b_____| 1 | a1 | b1 | 2 | a2 | b2 | 3 | a3 | b3 | 4 | a4 | b4 | 5 | | | 6 | | | 7 | | | 8 | | | 9 | | | 10 | | |
how query sql server?
fiddle here : http://sqlfiddle.com/#!3/9a9dd/1
with cte1 ( select 1 [no] union select [no]+1 cte1 [no]<10 ), cte2 ( select row_number() on (order (select null)) rn, a,b yourtable ) select c1.[no],a,b cte1 c1 left join cte2 c2 on c1.[no] = c2.rn
Comments
Post a Comment