September 10, 2010 at 2:19 am
I have a list id ID numbers contained in an xml document which i pass into a stored procedure.
I want to change the a column to a set value for ALL the id's contained in the xml list, but for some reason I cant get it to work. heres the sql in the stored procedure
EXEC sp_xml_preparedocument @idoc OUTPUT, @_xml
BEGIN TRANSACTION
UPDATE Table1
SET StatusID = @UpdateStatus
FROM OPENXML(@idoc,'/Root/id',1)
WITH (id bigint) ox
WHERE Table1.ID = ox.id
EXEC sp_xml_removedocument @idoc
the sp compiles ok and is created, yet when I pass in the xml list, nothing is updated. Can anyone see what im doing wrong here ?
September 10, 2010 at 2:37 am
Ive taken another look at the sql and modified it slightly to this
EXEC sp_xml_preparedocument @idoc OUTPUT, @_xml
BEGIN TRANSACTION
UPDATE Table1
SET StatusID = @UpdateStatus
WHERE Table1.ID IN
(SELECT ox.id FROM OPENXML(@idoc,'/Root/id')
WITH (id bigint) ox)
EXEC sp_xml_removedocument @idoc
COMMIT
but it still wont work, anyone have any idea why ?
September 10, 2010 at 4:27 am
Ive followed the suggestion from microsoft (http://support.microsoft.com/kb/315968/en-gb)
but it just will not change any data. Can anyone help ?
BEGIN TRY
EXEC sp_xml_preparedocument @idoc OUTPUT, @_xml
BEGIN TRANSACTION
UPDATE AdapterTransaction
SET StatusID = @UpdateStatus
FROM OPENXML(@idoc,'/Root/id')
WITH (id bigint) xmlTable
WHERE AdapterTransaction.TransactionID = xmlTable.id
EXEC sp_xml_removedocument @idoc
COMMIT
END TRY
September 10, 2010 at 5:05 am
please provide sample data so we have something to test against (xml string, table def of target data, some sample data and your expected output).
September 10, 2010 at 5:11 am
Input XML
<Root>
<id>3756</id>
<id>3757</id>
<id>3758</id>
<id>3759</id>
<id>3760</id>
<id>3761</id>
</Root>
Input Status value = 1
the table has a primary key column 'TransactionID' and a statusID column of type integer
Im expecting all rows with a matching id in the xml to have the statusid column set to 1
September 10, 2010 at 6:13 am
finally managed to solve this, heres the answer
BEGIN TRY
EXEC sp_xml_preparedocument @idoc OUTPUT, @_xml
BEGIN TRANSACTION
UPDATE AdapterTransaction
SET StatusID = @UpdateStatus
FROM OPENXML(@idoc,'/Root/id')
WITH (id bigint '.') xmlTable
WHERE AdapterTransaction.TransactionID = xmlTable.id
EXEC sp_xml_removedocument @idoc
COMMIT
END TRY
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply