0

Using below codes makes a table with one column as:

1
2
3
4
5
6
7
CREATE TABLE abc (a VARCHAR(8));
INSERT INTO abc VALUES(1),(2),(3),(4),(5),(6),(7)

But how we can use a method with using (1),(2),(3),(4),(5),(6),(7) , I mean something like 1:7 only?

Kermit
  • 33,827
  • 13
  • 85
  • 121
Essex Essex
  • 1
  • 1
  • 1

2 Answers2

4

Did anyone say recursion??

with rec as (
    select 1 i
    union all
    select i+1 from rec where i < 7
)
select * from rec
Community
  • 1
  • 1
Adriano Carneiro
  • 57,693
  • 12
  • 90
  • 123
0

If I am not wrong you are looking for a way to insert set of INT values in column in single batch. for example "insert 100 Identities in columnA." there is no predefined SQL SERVER function for that. but you can work around using any system table that you sure will have sufficient number rows you are looking for.

    SELECT rownum
    FROM
    (
        SELECT name,ROW_NUMBER() OVER (ORDER BY name) rownum
        FROM sysobjects so
    )q
    WHERE rownum <= 7
Anup Shah
  • 1,256
  • 10
  • 15