出错了:
服务器: 消息 8101,级别 16,状态 1,行 18
仅当使用了列的列表,并且 IDENTITY_INSERT 为 ON 时,才能在表 '#TMP2' 中为标识列指定显式值。
create table tmp1(ch_part,yield)
DECLARE @PART INT
DECLARE @YIELD INT
TRUNCATE TABLE TMP1
select ch_part, yield INTO #TMP2 from YIELD where Fa_PART = 1001
WHILE (exists (select yield from #TMP2))
BEGIN
declare mycursor1 cursor for select ch_part, yield from #TMP2
open mycursor1
fetch next from mycursor1 into @part, @yield
while (@@fetch_status = 0)
begin
DELETE #TMP2 WHERE CURRENT OF mycursor1
if not exists (select Fa_part from YIELD where Fa_part = @part)
insert into tmp1 values(@part, @yield)
else
INSERT #TMP2 SELECT CH_PART,YIELD*@yield FROM YIELD WHERE FA_PART = @PART
fetch next from mycursor1 into @part, @yield
END
CLOSE mycursor1
DEALLOCATE mycursor1
END
select * from tmp1