January 21, 2015 at 8:32 am
DECLARE @fileIds Xml =
'<Ids>
<Id>1</Id>
<Id>2</Id>
</Ids>',
@archiveId int = 1,
@archiveName varchar(255),
@idoc int
EXEC sp_xml_preparedocument @idoc OUTPUT, @fileIds
SELECT @archiveId , FileName FROM Files f
JOIN
(SELECT Id FROM
OPENXML(@idoc, '/Ids', 2)
WITH( Id int )) AS s
ON f.FileId = s.Id
I have the above code which returns only 1 row, I think the Openxml function does not return the Id 2 from the xml... What I'm doing wrong??
the file with fileid = 2 exists too in the files table
January 21, 2015 at 8:42 am
Try changing
SELECT Id FROM
OPENXML(@idoc, '/Ids', 2)
WITH( Id int )
to
SELECT Id FROM
OPENXML(@idoc, '/Ids/Id', 2)
WITH( Id int '.' )
____________________________________________________
Deja View - The strange feeling that somewhere, sometime you've optimised this query before
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537January 21, 2015 at 8:44 am
Now I don't get any result...
Thanks for answering
January 21, 2015 at 8:48 am
What happens when you run this?
DECLARE @fileIds Xml =
'<Ids>
<Id>1</Id>
<Id>2</Id>
</Ids>',
@archiveName varchar(255),
@idoc int
EXEC sp_xml_preparedocument @idoc OUTPUT, @fileIds
SELECT Id FROM
OPENXML(@idoc, '/Ids/Id', 2)
WITH( Id int '.' )
____________________________________________________
Deja View - The strange feeling that somewhere, sometime you've optimised this query before
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537January 21, 2015 at 8:48 am
Very strange the code now looks like this as you replied first time
(SELECT Id FROM
OPENXML(@idoc, '/Ids/Id', 2)
WITH( Id int '.')) AS s
ON f.FileId = s.Id
I made some changes but undo to what you said and now seems to work
I'm confuse can you explain please what '.' does?
Thanks a lot
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply