SQL Server 2012 - How to extract a value from an XML string? -
this seems basic, haven't been able find example works me, i'd appreciate advice.
i have sql server function determines various dates based on our fiscal year , today's date, , returns 1 row looks like... <row lastdayprevmonth="2015-04-30t00:00:00" lastdayprevmonthly="2014-04-30t00:00:00" ... />
in stored proc calls function, i've done...
declare @x xml set @x = dbo.getfiscalyeardates()
...but can't seem extract value of lastdayprevmonth.
i've tried dozens of variations of this: select row.item.value('lastdayprevmonth', 'varchar(30)')[1] foo @x.nodes('row/item')
... "as bar" @ end...
that particular syntax gives error "incorrect syntax near keywork 'as'", tweaks don't help.
thanks assistance, dudes!
declare @doc xml select @doc= ' <root> <row lastdayprevmonth="2015-04-30t00:00:00" lastdayprevmonthly="2014-04-30t00:00:00" /> </root> ' select lastdayprevmonth = y.i.value('(@lastdayprevmonth)[1]', 'datetime') , lastdayprevmonthly = y.i.value('@lastdayprevmonthly[1]', 'datetime') @doc.nodes('root/row') y(i)
Comments
Post a Comment