Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Sales Order Workshop Part IV


Sales Order Workshop Part IV

Author
Message
jacob sebastian
jacob sebastian
SSC-Addicted
SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)

Group: General Forum Members
Points: 472 Visits: 2523
I just posted a reply above, where i presented an example which extracts values from attributes and XML nodes.

.
jacob sebastian
jacob sebastian
SSC-Addicted
SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)

Group: General Forum Members
Points: 472 Visits: 2523
I just posted a reply above, which has an example of extracting values from xml attributes and nodes, using "value" method.

.
panesofglass
panesofglass
SSC Rookie
SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)

Group: General Forum Members
Points: 42 Visits: 104

Thanks for the additional info. That makes a lot of sense. One more question: how do you incorporate namespaces into the processing? Do you have to just pull the namespaces out, or can you include the, for example, 'my:element' in its entirety. Apologies if this has already been addressed. I didn't see it above.

Thanks,

Ryan


jacob sebastian
jacob sebastian
SSC-Addicted
SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)

Group: General Forum Members
Points: 472 Visits: 2523

Hi Ryan,

the following example shows how to take values from a namespace.

declare @x xml

set @x = '

<ns0:root xmlns:ns0="http://schemas.microsoft.com/sqlserver/2004/

07/adventure-works/ProductModelManuInstructionsModified">

<ns0:Location LocationID="100" SetupHours="10.4"

MachineHours="10.4" LaborHours="10.4" LotSize="10.4" />

</ns0:root>'

select

x.ns.value('@LocationID[1]', 'varchar(10)') as LocationID

from

@x.nodes('declare namespace ns0="http://schemas.microsoft.com/sqlserver/2004/

07/adventure-works/ProductModelManuInstructionsModified";/ns0:root/ns0:Location') as x(ns)



.
Hans Lindgren
Hans Lindgren
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1204 Visits: 366

tymberwyld:

Why not use NULLIF( LTrim(RTrim(Prefix)) , '' ) instead of Case When LTrim(RTrim(Prefix)) = '' Then Null Else LTrim(RTrim(Prefix)) End As Prefix?

Regards,

Hanslindgren





tymberwyld
tymberwyld
SSC Veteran
SSC Veteran (284 reputation)SSC Veteran (284 reputation)SSC Veteran (284 reputation)SSC Veteran (284 reputation)SSC Veteran (284 reputation)SSC Veteran (284 reputation)SSC Veteran (284 reputation)SSC Veteran (284 reputation)

Group: General Forum Members
Points: 284 Visits: 274
Heh, you got me, that would be easier...



sunil1978
sunil1978
SSC Veteran
SSC Veteran (284 reputation)SSC Veteran (284 reputation)SSC Veteran (284 reputation)SSC Veteran (284 reputation)SSC Veteran (284 reputation)SSC Veteran (284 reputation)SSC Veteran (284 reputation)SSC Veteran (284 reputation)

Group: General Forum Members
Points: 284 Visits: 131
I am using approach mentioned in post to do a master detail insert with following query,

INSERT INTO LISTDTL(ListDtl_ListHdrID,ListDtl_ProductID,ListDtl_ISBN_Number) SELECT @ListHdr_ID,P.PROD_PRODUCT_ID,ISBN.ISBNNumber FROM PRODUCT P INNER JOIN (SELECT ParamValues.ID.value('.','VARCHAR(20)') as ISBNNumber FROM @ValidISBN.nodes('/VALIDISBN/value') as ParamValues(ID) ) ISBN ON P.PROD_NUMBER=ISBN.ISBNNumber

where,

@ValidISBN='VALIDISBN Value 89869855898955 /value /VALIDISBN'



(This XML string. I could not write in proper XML as it was showing blank if it is written in proper XML format. This string is created in front end of application and is set to sql command parameter when using ExecuteNonQuery)

If @ValidISBN contains 7000 records, my insert query takes around 1 min or more.

How can I improve performance of my query.
Hans Lindgren
Hans Lindgren
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1204 Visits: 366
Hi,

Well, XML is not thought for performance. If you are processing 7000+ rows and you want real performance, you should use CSV files or similar files with much less overhead. You can even gain performance by having a fast XML -> CSV parser first in your chain.
Otherwise, try other T-SQL XML parsing approaches (like with OPENXML or similar) to find out which one is faster.



jacob sebastian
jacob sebastian
SSC-Addicted
SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)

Group: General Forum Members
Points: 472 Visits: 2523
Agreed with Hans. On large XML documents, OPENXML is found to be performing better than XQuery methods.

.
sunil1978
sunil1978
SSC Veteran
SSC Veteran (284 reputation)SSC Veteran (284 reputation)SSC Veteran (284 reputation)SSC Veteran (284 reputation)SSC Veteran (284 reputation)SSC Veteran (284 reputation)SSC Veteran (284 reputation)SSC Veteran (284 reputation)

Group: General Forum Members
Points: 284 Visits: 131
Thanks all for your reply. I reverted to CSV string and used a function to return table from it. This table is used in my join query. I was amazed to see CSV query completing insert in just 14 sec in comparison to 2:05 sec using XML string. Still not able to get why XML query is taking such a long time.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search