Note that there are some explanatory texts on larger screens.

plurals
  1. POBaseball XML to SQL query - optimize
    primarykey
    data
    text
    <p>source data looks comes from the following, freely available XML files describing major league baseball games.</p> <p><a href="http://gd2.mlb.com/components/game/mlb/year_2013/month_04/day_09/gid_2013_04_09_atlmlb_miamlb_1/inning/" rel="nofollow">http://gd2.mlb.com/components/game/mlb/year_2013/month_04/day_09/gid_2013_04_09_atlmlb_miamlb_1/inning/</a></p> <p>I have created a SQL Server table that contains a row for every GamePK/inning, with an XML column named PBP. Each file in the folder above becomes a row in this table. The query below is my attempt to parse the XML into a record set. It works but is very slow for a large number of rows, and very repetitive - seems like there should be a better way to do this without the UNION clause. Any help in improving/optimizing is appreciated</p> <pre><code>select i.GamePK ,inn.value('@num', 'int') as inning ,itop.value('1', 'int') as IsTop ,itop.value('@num', 'int') as abNum ,itop.value('@batter', 'int') as batter -- clip ,itoppit.value('@des', 'varchar(32)') as pitdesc ,itoppit.value('@id', 'int') as seq ,itoppit.value('@type', 'varchar(8)') as pittype -- clip from tblInnings i cross apply PBP.nodes('/inning') as inn(inn) cross apply inn.nodes('top/atbat') as itop(itop) cross apply itop.nodes('pitch') as itoppit(itoppit) union select i.GamePK ,inn.value('@num', 'int') as inning ,ibot.value('0', 'int') as IsTop ,ibot.value('@num', 'int') as abNum ,ibot.value('@batter', 'int') as batter -- clip ,ibotpit.value('@des', 'varchar(32)') as pitdesc ,ibotpit.value('@id', 'int') as seq ,ibotpit.value('@type', 'varchar(8)') as pittype --clip from tblInnings i cross apply PBP.nodes('/inning') as inn(inn) cross apply inn.nodes('bottom/atbat') as ibot(ibot) cross apply ibot.nodes('pitch') as ibotpit(ibotpit) </code></pre>
    singulars
    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