用循环语句生成字段值insert
SQL 如下:
create procedure InsertTest
as
begin
declare @i int
declare @s varchar(20)
set @i=1
while @i<=100
begin
select @s=cast(@i AS varchar(20))
insert into test (A,B,C,D) VALUES ('a'+@s,'b'+@s,'ccccc','ddddd')
SET @i=@i+1
end
end
这个简单循环。
CREATE TABLE #test (a INT,b VARCHAR(10),c VARCHAR(10),d VARCHAR(10))
GO
CREATE PROC insertdata
as
DECLARE @i INT
SET @i=1
WHILE (@i<=100)
BEGIN
INSERT INTO #test VALUES(@i,'aaa'+CAST(@i AS varchar),'cc','dd')
SET @i=@i+1
END
go
SELECT * FROM #test
你的描述不清楚啊,test是不是数据表?A,B字段是不是对应递增?C,D不变意思是都是空值,还是对某些现有值的选择?