Xml:
<?xml version="1.0" encoding="UTF-8"?> <root> <Physicians> <ddMA>ddN</ddMA> </Physicians> </root> Sql to update the XML:
If @makeApptVal != '' //this is provided from the user. 'ddN' OR 'ddY' BEGIN If @xml.value('(/root/Physicians/ddMA/text())[1]', 'varchar(50)') IS NOT NULL BEGIN Set @xml.modify('replace value of (/root/Physicians/ddMA/text())[1] with sql:variable("@makeApptVal")'); //if the value exists, which it will always exist, replace whatever if in there now with what the `makeApptVal` is. END Else BEGIN Set @xml.modify('insert text{sql:variable("@makeApptVal")} into (/root/Physicians/ddMA)[1]'); //if the value does exists, set the value of the dropdown with what the `makeApptVal` is (either ddN[index: 1] or ddY[index: 0]). END END Else BEGIN SET @xml.modify('delete (/root/Physicians/ddMA/text())[1]'); //instead of deleting it, just set the default value which is `ddN` at index 1 END The ddMA field is a dropdown field, which has two options:
Yes [index 0] No [index 1](this is set by default) What I am trying to do with the Sql is to check to see if @makeApptVal is either ddY or ddN. Set the index based of ddMA Xml node by what is provided. I know the above Sql queries is for a node which is text, but how can I modify so it works with the dropdownlist.
No comments:
Post a Comment