|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
XML field update errorWhen trying to update xml field that contains xml without schema I got the following error: XQuery: Only nillable elements or text nodes can be updated with empty sequence The code I was using: Update interface set messages.modify( 'replace value of (/Messages/Message[@Name = sql:variable("@ProfileName")]/Properties/Property[@Key = "Interval"]/@Value)[1] with sql:variable("@Interval")') Where InterfaceID = @InterfaceID @ProfileName variable is int and its value is NULL and what I want to get is: Value="" Here is XML i was updating: <Messages> <Message Name="111" Type="0"> <Properties> <Property Key="Interval" Value="10" /> <Property Key="Frequency" Value="" /> </Properties </Message> </Messages> what i want to get is <Messages> <Message Name="111" Type="0"> <Properties> <Property Key="Interval" Value="" /> <Property Key="Frequency" Value="" /> </Properties </Message> </Messages> Thanks in advance. Hello Alexander,
Yep, it means what it says: it can't nil out attribute, only a text node or an nillable elements value can be set to a null value for an integer. You can, however, do this: declare @IntervalP 3 set @IntervalP = 3 declare @Interval varchar(10) set @Interval = cast(@intervalP as varchar(10)) declare @ProfileName nvarchar(50) set @ProfileName ='111' declare @don xml set @don = '<Messages><Message Name="111" Type="0"><Properties><Property Key="Interval" Value="10" /><Property Key="Frequency" Value="" /></Properties></Message></Messages>' set @don.modify('replace value of (/Messages/Message[@Name=sql:variable("@ProfileName")]/Properties/Property[@Key ="Interval"]/@Value)[1] with sql:variable("@Interval")') select @don Thanks, Kent Tegels, DevelopMentor http://staff.develop.com/ktegels/ |
|||||||||||||||||||||||