Skip to content

Instantly share code, notes, and snippets.

@eriksimonic
Created March 10, 2019 15:38
Show Gist options
  • Save eriksimonic/f4857d3d576d08f2f8f7c7b8192dc6f9 to your computer and use it in GitHub Desktop.
Save eriksimonic/f4857d3d576d08f2f8f7c7b8192dc6f9 to your computer and use it in GitHub Desktop.
Clean duplicate cmsLanguageText if duplication occurs.

Crates a delete queries, so you can easily clean duplicate entries.. If you ware medeling with the cmsLanguageText.

Just for reference.

with c (UniqueId) as
(
select UniqueId from cmsLanguageText
group by UniqueId
having count(1) > 2
)
select
'delete from cmsLanguageText where UniqueId = ''' +cast( l.UniqueId as varchar(max)) + ''' and pk != '+cast( min(l.pk) as varchar(max)) +' and languageId = '+ cast(l.languageId as varchar(max)) +';',
l.UniqueId, l.value,l.languageId, min(l.pk) as pk, count(1) as Count
from cmsLanguageText l
inner join c
on c.UniqueId = l.UniqueId
group by l.UniqueId, l.value, l.languageId
order by l.UniqueId
go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment