我正在尝试制作表格的精确副本,但更改了 2 列的值。基本上我在 db 表中有 800 个条目,还需要 800 个条目,但我需要其中一列的值(Set_id 为 11),并且我需要另一个列的值来自动递增……但不幸的是,该列不是身份插入。我创建了一个临时表并将现有表复制到临时表中。然后,我尝试将临时表写回原始表,其中一列为 11,并尝试使 doctype id 列以 860 开头,然后每个条目自动递增一。我创建了这个游标:
declare @id int, @document char(30)
select @id = 860
declare documents cursor for
/* This will select all Non-Physician users */
select tag from cabinet..document_names
open documents
fetch next from documents into @document
while @@fetch_status <> -1
begin
select @id = @id +1
if not exists (select * from cabinet..document_names where set_id='11' and tag=@document)
insert into cabinet..document_names (TAG, TAGORDER, ACTIVE,QUEUE, REASON, FORM,DIRECT_VIEW,GLOBAL,FU_SIGN,SIGN_X,
SIGN_Y,SIGN_W,SIGN_H,ANNOTATE,doctype_id,CODE,CALCTABLE_ID, DOC_TYPE,SET_ID,SUSPEND_DELAY,Text_Editing,Restrict_Viewing,Viewing_Expire,
Viewing_Period , DocHdrLength,DocHdrSearchString,DocFtrLength,DocFtrPageNo,DocRuleId,Outbound,SigQueue,SigReason)
select TAG, TAGORDER, ACTIVE,QUEUE, REASON, FORM,DIRECT_VIEW,GLOBAL,FU_SIGN,SIGN_X,
SIGN_Y,SIGN_W,SIGN_H,ANNOTATE,@ID,CODE,CALCTABLE_ID, DOC_TYPE,'11',SUSPEND_DELAY,Text_Editing,Restrict_Viewing,Viewing_Expire,
Viewing_Period , DocHdrLength,DocHdrSearchString,DocFtrLength,DocFtrPageNo,DocRuleId,Outbound,SigQueue,SigReason from
cabinet..document_names_temp
fetch next from documents into @document
end
close documents
deallocate documents
它完全符合我的要求,除了 doctype id 重复为 861、861 等。我需要在每次进入原始表后将该数字增加一。任何关于我搞砸的地方的帮助都会受到赞赏!谢谢!