Good morning, I have found that I have duplicate attributes is some of the metadata.attribut table.
I found a great piece on the web concerning this, but I can't figure out how to the OUTPUT file to go to a certain document.
Here is the code I found
declare @fieldXml nvarchar(max), @otc int, @idoc int
declare curEntity cursor fast_forward for
select ObjectTypeCode, FieldXml from OrganizationUIBase where InProduction = 1
open curEntity
fetch next from curEntity into @otc, @fieldXml
while @@fetch_status = 0
begin
EXEC sp_xml_preparedocument @idoc OUTPUT, @fieldXml
if exists ( select name as field from OpenXML(@idoc, '/entity/fields/field') WITH (name nvarchar(64)) group by name having count(*) > 1 )
select @otc as otc, name as field, count(*) as occurences
from OpenXML(@idoc, '/entity/fields/field') WITH (name nvarchar(64))
group by name
having count(*) > 1
EXEC sp_xml_removedocument @idoc
fetch next from curEntity into @otc, @fieldXml
end
close curEntity
deallocate curEntity
I found the duplicates using this:
select e.name as entity, a.name as attribute, a.attributeid,count(*)
from attribute a join entity e on a.entityid = e.entityid
group by e.name, a.name, a.attributeid
having count(*)> 1
How can I view the fields that are duplicate using the OUPUT file?
"fetch nextfrom curEntity into @otc, @fieldXml"