dbTalk Databases Forums  

How is fastest way to construct an XML node then a bunch of slow xquery modify statements?

microsoft.public.sqlserver.clients microsoft.public.sqlserver.clients


Discuss How is fastest way to construct an XML node then a bunch of slow xquery modify statements? in the microsoft.public.sqlserver.clients forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
DR
 
Posts: n/a

Default How is fastest way to construct an XML node then a bunch of slow xquery modify statements? - 10-30-2007 , 02:30 PM






How is fastest way to construct an XML node then a bunch of slow xquery
modify statements?

This SQL Server 2005 logic is rather slow to simply add a new item to an xml
document. Any way to do this all in one statement and faster for creating a
new node without having to re-select to set the attribute values?

set @currentItems.modify('insert <Item></Item> as first into
(/Items/ParentItem[(@id=sql:variable("@parentItemID"))])[1]')
set @currentItems.modify('insert (attribute id {sql:variable("@itemID")},
attribute length {sql:variable("@metadataLength")}, attribute activityDate
{sql:variable("@activityDate_xml")}) into
(/Items/ParentItem[(@id=sql:variable("@parentItemID"))]/Item)[1]')
set @currentItems.modify('replace value of
(/Items/ParentItem[(@id=sql:variable("@parentItemID"))]/@totalCount)[1] with
((/Items/ParentItem[(@id=sql:variable("@parentItemID"))]/@totalCount)[1] +
1)')
set @currentItems.modify('replace value of
(/Items/ParentItem[(@id=sql:variable("@parentItemID"))]/@lastModified)[1]
with sql:variable("@lastModified_xml")')


One idea is to do this in a CLR function that uses a simple string builder
to create the node, but then it has to be reserialized and there is CLR
overhead. Any ideas on how to make this faster?



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.