日期:2014-05-16 浏览次数:20489 次
CREATE TABLE a(aa int)
INSERT INTO dbo.a
( aa )
VALUES ( 3 -- aa - int
)
declare @i INT
DECLARE @count INT
DECLARE @sql1 VARCHAR(2000),@sql2 VARCHAR(2000),@sql3 VARCHAR(2000)
SELECT @count=aa FROM a
--PRINT @sql1
set @i=1
while @i<=@count
begin
SET @sql2=' union all select * from a'
--PRINT @sql2 ----1
set @i=@i+1
--PRINT @sql2 ----2
end
PRINT @sql2 ------3
CREATE TABLE a(aa int)
INSERT INTO dbo.a
( aa )
VALUES ( 3 -- aa - int
)
declare @i INT
DECLARE @count INT
DECLARE @sql1 VARCHAR(2000),@sql2 VARCHAR(2000),@sql3 VARCHAR(2000)
select @sql2=''
SELECT @count=aa FROM a
--PRINT @sql1
set @i=1
while @i<=@count
begin
SET @sql2=@sql2+' union all select * from a'
--PRINT @sql2 ----1
set @i=@i+1
--PRINT @sql2 ----2
end
PRINT @sql2 ------3
CREATE TABLE a(aa int)
INSERT INTO dbo.a
( aa )
VALUES ( 3 -- aa - int
)
declare @i INT
DECLARE @count INT
DECLARE @sql1 VARCHAR(2000),@sql2 VARCHAR(2000),@sql3 VARCHAR(2000)
SELECT @count=aa FROM a
--PRINT @sql1
set @i=1
while @i<=@count
begin
SET @sql2=' union all select * from a'
--PRINT @sql2 ----1
--PRINT @sql2 ----2
set @i=@i+1
PRINT @sql2 ------3
END
DROP TABLE a
GO