tags:

views:

55

answers:

2

I store an XML string in a column in my SQL Server database. I'm trying to run an UPDATE statement that will make a certain field into Upper Case. I can do that easily during a SELECT but can't get it to work with an update.

This SELECT statement works
select Upper(XmlTest.value('(/CodeFiveReport/Owner/@UnitNumber)[1]', 'varchar(10)')) as UnitNumber from uploadreport

But I want to update the XML as that permanently
Update table Set XmlString.Modify('replace value of (/Root/Node/@Field)[1] with ?

A: 

Use the XQuery function upper-case

MasterGaurav
I saw that function but wasn't sure where to use it... kept getting function not found error when I ran the query...
mint
A: 

upper-case was added to SQL Server in SQL Server 2008, so there's no good solution prior to that unless you want to use cursors. The following works in SQL Server 2008:

declare @xml xml

set @xml = N'<CodeFiveReport><Owner UnitNumber="Mixed"/></CodeFiveReport>'
select T1.C1.value('upper-case((/CodeFiveReport/Owner/@UnitNumber)[1])', 'varchar(10)') from @xml.nodes('/') T1(C1)

SET @xml.modify('
                replace value of (/CodeFiveReport/Owner/@UnitNumber)[1]
                with xs:string(upper-case((/CodeFiveReport/Owner/@UnitNumber)[1]))
                ')

select @xml
Emil Lerch
aww i see, I'm using 2005; probably should have mentioned that in the original post.
mint