1.sql 查询和删除多条字段的重复语句

查询

select a.* from Base_UserDeptRole a inner join(
   select DeptRoleId,UserId  from Base_UserDeptRole(表)
   group by DeptRoleId,UserId
   having count(*)>1) tem on tem.UserId=a.UserId and tem.DeptRoleId=a.DeptRoleId

删除

select distinct DeptRoleId,UserId into #Tmp from Base_UserDeptRole(表)
delete  Base_UserDeptRole
insert into Base_UserDeptRole (
Id,DeptRoleId,UserId,CreatedOn,CreatedById,ModifiedOn,ModifiedById
)
select NEWID(),temp.DeptRoleId,temp.UserId,GETDATE(),00000000-0000-0000-0000-000000000001,GETDATE(),00000000-0000-0000-0000-000000000001  from #Tmp temp

 

1.sql 查询和删除多条字段的重复语句,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。