感觉上面的对数据库的操作过于多,修改如下:DECLARE @Name VARCHAR(10)DECLARE @TypeName1 VARCHAR(10)DECLARE @Sql1 VARCHAR(8000)DECLARE @Sql VARCHAR(8000)DECLARE @TypeName VARCHAR(10)SET @Sql1 = 'CREATE TABLE table2(部门 varchar(10),人员 varchar(200))'EXEC(@Sql1)SET @Sql1 = 'INSERT INTO table2 (部门,人员) VALUES ('''DECLARE curType CURSOR READ_ONLY FORWARD_ONLY FOR SELECT 部门,人员 FROM 表 ORDER BY 部门OPEN curTypeFETCH NEXT FROM curType INTO @TypeName,@NameSET @TypeName1=@TypeNameSET @Sql=''WHILE @@Fetch_Status = 0BEGIN--PRINT @TypeName--PRINT @NameIF @TypeName1=@TypeNameBEGINIF @Sql=''BEGINSET @Sql = @NameENDELSEBEGINSET @Sql = @Sql +',' + @NameENDENDELSEBEGINSET @Sql=@Sql1+@TypeName1+''','''+@Sql+''')'EXEC(@Sql)--PRINT @SqlSET @Sql=''SET @Sql = @NameENDSET @TypeName1=@TypeNameFETCH NEXT FROM curType INTO @TypeName,@NameENDSET @Sql=@Sql1+@TypeName1+''','''+@Sql+''')'EXEC(@Sql)--PRINT @SqlCLOSE curTypeDEALLOCATE curType