Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

how to read xml variable using openxml Expand / Collapse
Author
Message
Posted Friday, December 14, 2012 9:28 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, April 01, 2014 2:04 AM
Points: 48, Visits: 130
Hi,

I have a xml like this.

<DocumentElement>
<tLockhistory>
<lockrequesteddate>2012-12-14T00:00:00+05:30</lockrequesteddate>
<lockexpirydate>2012-12-29T00:00:00+05:30</lockexpirydate>
<createddate>2012-12-14T00:00:00+05:30</createddate>
</tLockhistory>
<tLockhistory>
<lockrequesteddate>2012-12-14 00:00:00</lockrequesteddate>
<lockexpirydate>2012-12-29 00:00:00</lockexpirydate>
<createddate>2012-12-14 00:00:00</createddate>
</tLockhistory>
</DocumentElement>

output is this.

lockrequesteddate lockexpirydate
----------------------- -----------------------
2012-12-13 18:30:00.000 2012-12-28 18:30:00.000
2012-12-14 00:00:00.000 2012-12-29 00:00:00.000

Note:
first row is the one really passed from the XML,
second row was added by me to check where is the issue.

My Question is:
How can I handle the XML date values, where the system reads a date value as a value which actually one day previous to the given date.

any immediate suggestion would be a great help to me.

Thanks in advance.
Post #1396733
Posted Friday, December 14, 2012 6:02 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, April 04, 2014 5:46 PM
Points: 2, Visits: 15
Hola,

No entiendo bien tu pregunta, espero te pueda ayudar esto, no hablo ni escribo bien el ingles

select
campo.value('(/Encabezado/Heads_dependiendo_arbol_del_XML)[1]','tipo_dato'')
from tabla

y de ahi ya podrias manejar tu fecha a tu gusto, adicional, te recomentaria crear una #temp para mejor manejo.

Saludos
Post #1396845
Posted Friday, December 14, 2012 6:47 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 8:55 PM
Points: 22,492, Visits: 30,199
prabhu.st (12/14/2012)
Hi,

I have a xml like this.


<DocumentElement>
<tLockhistory>
<lockrequesteddate>2012-12-14T00:00:00+05:30</lockrequesteddate>
<lockexpirydate>2012-12-29T00:00:00+05:30</lockexpirydate>
<createddate>2012-12-14T00:00:00+05:30</createddate>
</tLockhistory>
<tLockhistory>
<lockrequesteddate>2012-12-14 00:00:00</lockrequesteddate>
<lockexpirydate>2012-12-29 00:00:00</lockexpirydate>
<createddate>2012-12-14 00:00:00</createddate>
</tLockhistory>
</DocumentElement>


output is this.

lockrequesteddate lockexpirydate
----------------------- -----------------------
2012-12-13 18:30:00.000 2012-12-28 18:30:00.000
2012-12-14 00:00:00.000 2012-12-29 00:00:00.000

Note:
first row is the one really passed from the XML,
second row was added by me to check where is the issue.

My Question is:
How can I handle the XML date values, where the system reads a date value as a value which actually one day previous to the given date.

any immediate suggestion would be a great help to me.

Thanks in advance.


The first time above is in UTC time. It is the time on the system expressed with an offset. If you add the offset to the time displayed (2012-12-13 18:30:00.000 + 5:30) that will be 2012-12-14 00:00:00.000.

Other than that, I can't be much help as I am learning XML and XML processing myself.



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1396848
Posted Friday, December 14, 2012 7:26 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 11:47 PM
Points: 35,959, Visits: 30,252
jos.moy (12/14/2012)
Hola,

No entiendo bien tu pregunta, espero te pueda ayudar esto, no hablo ni escribo bien el ingles

select
campo.value('(/Encabezado/Heads_dependiendo_arbol_del_XML)[1]','tipo_dato'')
from tabla

y de ahi ya podrias manejar tu fecha a tu gusto, adicional, te recomentaria crear una #temp para mejor manejo.

Saludos


Gosh... it would really be nice if I could actually read this. Would you mind replying in English, please?


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

"Change is inevitable. Change for the better is not." -- 04 August 2013
(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1396851
Posted Friday, December 14, 2012 7:33 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, April 04, 2014 5:46 PM
Points: 2, Visits: 15
Hello

In a SQL to get the fields of XML to SQL query would be like this, not if you really want to take SQL.


select
campo.value('(/Encabezado/Heads_tree_XML)[1]','Data_type'')
from tabla

I hope to help you
Post #1396853
Posted Saturday, December 15, 2012 10:00 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 11:47 PM
Points: 35,959, Visits: 30,252
jos.moy (12/14/2012)
Hello

In a SQL to get the fields of XML to SQL query would be like this, not if you really want to take SQL.


select
campo.value('(/Encabezado/Heads_tree_XML)[1]','Data_type'')
from tabla

I hope to help you


Thanks.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

"Change is inevitable. Change for the better is not." -- 04 August 2013
(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1396900
Posted Saturday, December 15, 2012 5:13 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Yesterday @ 5:20 PM
Points: 1,651, Visits: 5,202
As you don't mention exactly what you are trying to achieve, it is hard to give a definite answer, but my guess from your desire to see the date as the 14th, not the 13th is that you want to show it as local time for the +05:30 time zone, in which case, just ignore the timezone...


declare @xml xml ='<DocumentElement>
<tLockhistory>
<lockrequesteddate>2012-12-14T00:00:00+05:30</lockrequesteddate>
<lockexpirydate>2012-12-29T00:00:00+05:30</lockexpirydate>
<createddate>2012-12-14T00:00:00+05:30</createddate>
</tLockhistory>
<tLockhistory>
<lockrequesteddate>2012-12-14 00:00:00</lockrequesteddate>
<lockexpirydate>2012-12-29 00:00:00</lockexpirydate>
<createddate>2012-12-14 00:00:00</createddate>
</tLockhistory>
</DocumentElement> '

-- selecting the value as CHAR(19) will take the date and time, but drop the timezone information, giving you the "local" time.
select cast(nd.value('(./lockrequesteddate/text())[1]','char(19)') as datetime) as lockrequesteddate
from @xml.nodes('/DocumentElement/tLockhistory') as x(nd)




MM


  • MMGrid Addin
  • MMNose Addin


  • Forum Etiquette: How to post Reporting Services problems
  • Forum Etiquette: How to post data/code on a forum to get the best help - by Jeff Moden
  • How to Post Performance Problems - by Gail Shaw

  • Post #1396927
    Posted Monday, December 17, 2012 3:16 AM
    SSC Rookie

    SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

    Group: General Forum Members
    Last Login: Tuesday, April 01, 2014 2:04 AM
    Points: 48, Visits: 130
    Hi all,

    thanks for your spending your finest time, I am sorry about "not giving my question clearly", but I have got some valuable tips from your replies that to avoid the Time Zone.

    Thanks again for your time.

    --Prabhu.st
    Post #1397175
    « Prev Topic | Next Topic »

    Add to briefcase

    Permissions Expand / Collapse