Skip to content Skip to sidebar Skip to footer

How To Add Blank Rows When Select Query Sql

Example : when I type : select number, city from user The results in the get is 3 rows. How to select the row that I can be automatically filled in 8 rows? What if using a loop

Solution 1:

While I don't understand the cause of this task, anyway you can do it like :

DECLARE@tTABLE ( ID INT )
DECLARE@cINT=8INSERTINTO@tVALUES  ( 1 ),
        ( 2 ),
        ( 3 );
WITH    cte
          AS ( SELECT1AS rn
               UNIONALLSELECT   rn +1FROM     cte
               WHERE    rn <=@c
             )
    SELECT TOP ( @c )
            *FROM    ( SELECT    ID
              FROM@tUNIONALLSELECTNULLFROM      cte
            ) t
    ORDERBY ID DESC

Output:

ID
321NULLNULLNULLNULLNULL

Post a Comment for "How To Add Blank Rows When Select Query Sql"