日期:2014-05-18  浏览次数:20720 次

好傻的WHILE循环插入,谁能帮我把这个WHILE给变成一句话插入?
DECLARE   @A1   INT
DECLARE   @A2   INT
SELECT   @A1   =   MIN(   ISNULL(AA00100,   0)   ),   @A2   =   MAX(AA00100)   FROM   AA001   WHERE   STATUS   =   1
CREATE   TABLE   #T
(
ID   int   IDENTITY(1,1),
        WORKCODE   int   not   null,
)
---------------------------
WHILE   @A1   <   @A2
BEGIN
INSERT   INTO   #T   (WORKCODE)   VALUES   (@A1)
SET   @A1=   @A1+1
END
---------------------------
SELECT   *   FROM   #T
DROP   TABLE   #T


------解决方案--------------------
select identity(int,1,1) as id
into #t
from sysobjects
------解决方案--------------------
DECLARE @a INT
DECLARE @b INT
SELECT @a=ISNULL(MIN(AA00100),0),
@b=MAX(AA00100)
FROM AA001 WHERE STATUS = 1

SELECT IDENTITY(INT,1,1) AS id,
@a AS WORKCODE
INTO dbo.#
FROM syscolumns
WHERE id <=@b
AND id> =@a

SELECT * FROM #