当前位置: 代码迷 >> Sql Server >> 好傻的WHILE循环插入,哪位高手能帮小弟我把这个WHILE给变成一句话插入
  详细解决方案

好傻的WHILE循环插入,哪位高手能帮小弟我把这个WHILE给变成一句话插入

热度:48   发布时间:2016-04-27 16:58:48.0
好傻的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 <[email protected]
AND id> [email protected]

SELECT * FROM #
  相关解决方案