Return to Snippet

Revision: 44566
at April 14, 2011 04:00 by kashif21


Initial Code
Adding element into the XML DATA
insert 
      Expression1 (
                 {as first | as last} into | after | before
                                    Expression2
                )

SET @xmlDoc.modify('
    insert element UpdateDatetime {"2010-10-28T13:49:27.330"} before or after 
    (/t/AuditID)[1]
')
SET @xmlDoc.modify('
   insert <UpdateDatetime>2010-10-28T13:49:27.330</UpdateDatetime>
	as last  or as first or      
	into(/t)[1]')
IF (@xmlDoc.exist('/t/UpdateDatetime')=0)
	BEGIN	
	SET @xmlDoc.modify('
	insert <UpdateDatetime>2010-10-28T13:49:27.330</UpdateDatetime>
	as last       
	into(/t)[1]')
	END

*Adding element with dynamic data from the sp parameters with condition.

IF (@xmlDoc.exist('/t/UpdateDatetime')=0)
	BEGIN	
	SET @xmlDoc.modify('
	insert element UpdateDatetime {sql:variable("@dtmCurrentDate")} 
	as last       
	into(/t)[1]')
	END

Initial URL

                                

Initial Description

                                

Initial Title
Xml element insertion in XML DATA

Initial Tags
data, xml

Initial Language
SQL