我想从同一张桌子上复制记录。如果parentID为null,那么我希望用另一个parentName复制它的父级和子级(我将使用替换关键字)。
如果它不是null,那么如果仅在父父中不存在相同的父文件,那么我希望将其复制到相同的父类中。
create table #Table(ID int primary key , Name varchar(10),ParentID int )
insert into #Table
select 1,'Suresh', -1
union
select 2,'Naresh', 1
union
select 3,'John', 1
union
select 4,'Kumar',3
union
Select 5,'Dale John',3
select * from #Table
ID Name ParentID
-------------------
1 Suresh -1
2 Naresh 1
3 John 1
4 Kumar 3
5 Dale John 3ID = 1,那么所有ID子表都应该插入到同一个表中,如果Name not "Suresh"和ParentID not -1.ID = 3,那么ID 3和Name and ParentID not John & 1应该插入到同一个表中发布于 2015-08-05 04:46:03
把它们放到临时表中,并将它们连接起来。如果不存在(--),则插入表中。
https://stackoverflow.com/questions/31793289
复制相似问题