xml - SQL Server XQuery check data values before insert -


this on sql server 2012.

i have tsql create xquery statement shred , insert xml

the code looks this:

declare @xmlasxml xml set @xmlasxml = '       <data store="r262">         <s item1="10" item2="-1" />         <s item1="33.2" item2="55"  />       </data> '  insert tablex(oldprice, price)     select        c.value('@item1[1]','decimal(15,2)') oldprice,        c.value('@ut[1]','int') price           @xmlasxml.nodes('/data/s') t(c) 

i want add data validation insert statement above (i don't want land data , have churn through again validate every data point)...

when data validation here's i'm saying:

  • if value item1 between 1 , 15 use insert otherwise insert null
  • if value item2 between -10 , 1000 use insert otherwise insert null.

i have see information on xquery think xquery has conditional logic can handle none of example have found align way i'm building , doing insert / select statement.

if there better way, i'm - long don't have shred data twice.

thanks in advance time! hope out there can me knock out!

declare @xmlasxml xml     set @xmlasxml = '           <data store="r262">             <s item1="10" item2="-1" />             <s item1="33.2" item2="55"  />           </data>';  ;with tmp (     select c.value('@item1[1]','decimal(15,2)') oldprice,            c.value('@ut[1]','int') price       @xmlasxml.nodes('/data/s') t(c) )     insert tablex (oldprice, price)      select case when oldprice between 1 , 15 oldprice end,            case when price between -1 , 1000 price end       tmp; 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -