重复从select语句中重复获取的数据块

时间:2015-04-28 16:35:57

标签: sql repeat

1)我有以下查询

select CRESTACode,Latitude,Longitude   from airgeography..tgeography where countryname in (
'St. Maarten') and crestacode is not Null 

结果:

CRESTACode  Latitude    Longitude
6           18.035187    -63.076599

如何多次重复此数据以在表格中获取3000行相同的数据?

1 个答案:

答案 0 :(得分:0)

虽然它可能很昂贵:

DECLARE @InsertNum INT 
SET @insertnum = 3000

select CRESTACode,Latitude,Longitude   
INTO #tablex
from airgeography..tgeography 
where countryname in ('St. Maarten') 
  and crestacode is not Null 

WHILE (@InsertNum <> 0 )
    BEGIN 
        INSERT INTO #Tablex 
        SELECT CRESTACode,Latitude,Longitude 
        FROM Tablex;

        SET @insertNum = @InserTNum - 1
        Print @InsertNum
    END 

SELECT * FROM #tablex