declare @xml xml = '
<person id="10">
<dwelling>
<street>S</street>
<city>C</city>
<emptynode></emptynode>
<emptynode/>
</dwelling>
<ssn>123-232-232</ssn>
</person>
'
;with C(NodeName, NewNodeName) as
(
select distinct T.N.value('local-name(.)', 'nvarchar(max)'),
upper(T.N.value('local-name(.)', 'nvarchar(max)'))
from @xml.nodes('//*') as T(N)
)
select @xml = replace(replace(replace(replace(cast(@xml as nvarchar(max)),
'<' +NodeName+'/>', '<' +NewNodeName+'/>'), -- Empty node
'<' +NodeName+' ' , '<' +NewNodeName+' ' ), -- Start node with attribute
'<' +NodeName+'>' , '<' +NewNodeName+'>' ), -- Start node no attribute
'</'+NodeName+'>' , '</'+NewNodeName+'>' ) -- End node
from C