Click here to Skip to main content
15,889,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI,
i am getting following xml from front end
SQL
<root>
<row DeptID = '319'  WeekDayID='1' SchedulePriority= '7' />
<row DeptID = '319'  WeekDayID='2' SchedulePriority= '6' />
</root>

for inserting written following code in stored procedure
SQL
declare @i int                         
		EXEC SP_XML_PREPAREDOCUMENT @i OUTPUT	 
		INSERT INTO temp
			 (col1,col2,col3)             
		SELECT
	        TempInsert.Item.value('@col1', 'int'),
	        TempInsert.Item.value('@col2', 'int'),
	        TempInsert.Item.value('@col3', 'int')	        
		FROM @XMLInsertion.nodes('/root/row') AS TempInsert(Item)
		EXEC SP_XML_REMOVEDOCUMENT @i

it works and inserted successfully
i need to update the table using the same xml
any suggestions

Thanks in Advance
Posted

1 solution

Hello Friend,
Using SQL CTE(Common table Expression) you can do this thing. below i provide some sample code as per your requirement.
SQL
;WITH CTE AS
    (
        SELECT
            t.n.value('@DeptID', 'varchar(10)') as DeptID,
            t.n.value('@SchedulePriority', 'varchar(10)') as WeekDayID
        FROM @XMLInsertion.nodes('/root/*') as t(n)
    )
    UPDATE T
        SET SCHEDULEPRIORITY = C.WeekDayID --Write a field name which you want to update
    FROM TEMP AS T
        INNER JOIN CTE AS C
    ON T.DEPTID = C.DEPTID

    SELECT * FROM TEMP
 
Share this answer
 
Comments
a.pkumar 10-Mar-14 7:07am    
Hi thanks,its working fine

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900