Note that there are some explanatory texts on larger screens.

plurals
  1. PODoes using nullif() statements with xquery in SQL Server ruin xquery optimization?
    primarykey
    data
    text
    <p>I have the following block of dynamic SQL in SQL Server 2008 (as part of a larger query):</p> <pre><code>insert into '+@schema+'.HP_Payers (HeadingID, PayerName, PayerID_Qualifier, PayerID, Address1, Address2, City, StateCode, ZipCode) select @headingID as HeadingID, nullif(c.value(''Name'', ''varchar(60)''), '''') as PayerName, nullif(c.value(''ID_Qualifier'', ''varchar(2)''), '''') as PayerID_Qualifier, nullif(c.value(''ID_Code'', ''varchar(80)''), '''') as PayerID, nullif(c.value(''Address1'', ''varchar(55)''), '''') as Address1, nullif(c.value(''Address2'', ''varchar(55)''), '''') as Address2, nullif(c.value(''City'', ''varchar(30)''), '''') as City, nullif(c.value(''StateCode'', ''char(2)''), '''') as StateCode, nullif(c.value(''ZipCode'', ''varchar(15)''), '''') as ZipCode from '+@schema+'.IntegrationQueue cross apply InputValue.nodes(''/ROOT/Payer'') t(c) where QueueID = @queueID </code></pre> <p>which inserts the correct data from the given node in the 'from' statement into a new table. The entire query itself ran a set of 10 XML files about 10 seconds faster than it did before I added the nullif() statements. I also found this tidbit of info on MS documentation regarding xquery optimization:</p> <p><em>The value() method calls must appear contiguously in a SELECT list to be merged. The execution of non-contiguous value() methods are not combined.</em></p> <p>So my question is does placing these nullif() statements essentially ruin this performance gain described here? Any help would be appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload