Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is the below thing possible?

I have a long XML string from which I select data. This data is the updated rows for a table, would it be possible to do something like this:
SQL
EXEC sp_xml_preparedocument @Handle OUTPUT, @Tags

UPDATE
    Pharmacy.Bins
SET
FROM
    (SELECT 
	    Notes 
    FROM 
		OPENXML(@Handle,'/data/Bins',2) 
		WITH (BinID int, ClosetID int, Notes nvarchar(MAX))
	) AS O
    JOIN Pharmacy.Bins AS B
        ON O.BinID = B.BinID
	)
Posted
Updated 14-Jun-10 4:37am
v2
Comments
Sandeep Mewara 14-Jun-10 10:39am    
It would be nice if you can add what exactly you are trying to achieve here? What do you have and what is the end result expected?

1 solution

It is difficult to look here and tell if it's possible or not. Please have a look at the details of using XML in SQL here:
MSDN: XML Support in Microsoft SQL Server 2005[^]

You should get an idea of what things are possible.
 
Share this answer
 
Comments
Mustafa Ismail Mustafa 15-Jun-10 5:19am    
No you missed out on my intent Sandeep.

The way I thought of it was this:

1. Selects return a "tabular" result set
2. I can update one table from another
3. I should be able to perform the same but from a select statement, which happens to retrieve data from an XML string

So, I figured it would be something like this:

UPDATE [table name]
SET
FROM
(SELECT statement returning required data from XML)
JOIN
(Join)

Makes more sense now?

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