sql server - XML Attributes to SQL -


i've seen posts similar i'm ask, can't find solves problem. i've seen (and duplicated) getting xml tags sql, not getting attributes of tags sql.

background: use program runs "events" based on each event's schedule. schedules in xml. ultimately, i'm trying compare last time given event ran last time should have run, based on schedule. once schedules out of xml , table (or tables), i'm confident can take there. but, i'm struggling first step.

below xml i'm trying table (or tables). appreciated!!

<schedule lastmodified="2016-06-27t21:02:10.6041531z" timezone="(utc-06:00) central time (us &amp; canada)" convertedtoutc="true" type="weekly">     <beginning startdate="2016-05-26t22:26:00.0000000" />     <block blocktype="allday" interval="10" intervaltype="minute" settype="inclusive" start="15:00:00" end="17:00:00" duration="02:00:00" />     <interval type="weekly" recureveryx="1" sunday="false" monday="true" tuesday="true" wednesday="true" thursday="true" friday="true" saturday="false" />     <ending type="noenddate" /> </schedule> 

don't know, have issues... reading xml rather trivial (did not code of values, you'll idea):

declare @mockup table(yourxml xml); insert @mockup values (n'<schedule lastmodified="2016-06-27t21:02:10.6041531z" timezone="(utc-06:00) central time (us &amp; canada)" convertedtoutc="true" type="weekly">     <beginning startdate="2016-05-26t22:26:00.0000000" />     <block blocktype="allday" interval="10" intervaltype="minute" settype="inclusive" start="15:00:00" end="17:00:00" duration="02:00:00" />     <interval type="weekly" recureveryx="1" sunday="false" monday="true" tuesday="true" wednesday="true" thursday="true" friday="true" saturday="false" />     <ending type="noenddate" /> </schedule>');  select m.yourxml.value(n'(/schedule/@lastmodified)[1]',n'datetime') schedule_lastmodified       ,m.yourxml.value(n'(/schedule/@timezone)[1]',n'nvarchar(max)') schedule_timezone       ,m.yourxml.value(n'(/schedule/beginning/@startdate)[1]',n'datetime') beginning_startdate       ,m.yourxml.value(n'(/schedule/block/@blocktype)[1]',n'nvarchar(max)') block_blocktype       ,m.yourxml.value(n'(/schedule/block/@interval)[1]',n'int') block_interval       ,m.yourxml.value(n'(/schedule/interval/@type)[1]',n'nvarchar(max)') interval_type @mockup m; 

if not solution, please edit question: add own attempt, wrong output , expected output. explanation did not make clear me...


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -