Generate empty row (null) in sql server

Asked

Viewed 904 times

1

I don’t have much knowledge of sql, but I need to do the following procedure:

  • User gives a number.
  • Sql generates the amount entered by the blank/null record user.
  • After generated the blank records, run an sql for query.

In the last item the sql query I can do. But I need to know how to run only after finished generating the blank records.


Case: The library uses a label sheet containing 30 labels. So if she used 5 sheet labels, I need 5 blank record to print nothing and from the sixth record start printing the query result.

2 answers

2


You can generate a table with numerical sequences (omitting your data) and link with your original search.
The TOP 10 you will specify how much you want.

WITH gerador (id) AS (
     SELECT 1
     UNION ALL
     SELECT id + 1
     FROM gerador
     WHERE id < 1000000
  )
  SELECT TOP 10 NULL 'CAMPO_1', NULL 'CAMPO_2', NULL 'CAMPO_3' FROM gerador
  UNION ALL
  SELECT SEU_CAMPO_1, SEU_CAMPO_2, SEU_CAMPO_3 FROM SUA_TABELA
  OPTION ( MAXRECURSION 0 )
GO

-1

Friend, and if it is not, the Select record coming before the NULL lines, limiting a maximum value of lines(10 for example). That is, dynamic NULL lines, if the record has 8 lines, the query should bring only 2 NULL lines if it considers a limit of 10 space lines.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.