SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


how to read xml variable using openxml


how to read xml variable using openxml

Author
Message
prabhu.st
prabhu.st
Right there with Babe
Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)

Group: General Forum Members
Points: 784 Visits: 310
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.
jos.moy
jos.moy
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
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
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (150K reputation)SSC Guru (150K reputation)SSC Guru (150K reputation)SSC Guru (150K reputation)SSC Guru (150K reputation)SSC Guru (150K reputation)SSC Guru (150K reputation)SSC Guru (150K reputation)

Group: General Forum Members
Points: 150915 Visits: 39301
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.

Cool
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)
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (341K reputation)SSC Guru (341K reputation)SSC Guru (341K reputation)SSC Guru (341K reputation)SSC Guru (341K reputation)SSC Guru (341K reputation)SSC Guru (341K reputation)SSC Guru (341K reputation)

Group: General Forum Members
Points: 341035 Visits: 42658
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.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
jos.moy
jos.moy
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
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
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (341K reputation)SSC Guru (341K reputation)SSC Guru (341K reputation)SSC Guru (341K reputation)SSC Guru (341K reputation)SSC Guru (341K reputation)SSC Guru (341K reputation)SSC Guru (341K reputation)

Group: General Forum Members
Points: 341035 Visits: 42658
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.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
mister.magoo
mister.magoo
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18024 Visits: 7928
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


select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);




  • 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

  • prabhu.st
    prabhu.st
    Right there with Babe
    Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)

    Group: General Forum Members
    Points: 784 Visits: 310
    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
    Go


    Permissions

    You can't post new topics.
    You can't post topic replies.
    You can't post new polls.
    You can't post replies to polls.
    You can't edit your own topics.
    You can't delete your own topics.
    You can't edit other topics.
    You can't delete other topics.
    You can't edit your own posts.
    You can't edit other posts.
    You can't delete your own posts.
    You can't delete other posts.
    You can't post events.
    You can't edit your own events.
    You can't edit other events.
    You can't delete your own events.
    You can't delete other events.
    You can't send private messages.
    You can't send emails.
    You can read topics.
    You can't vote in polls.
    You can't upload attachments.
    You can download attachments.
    You can't post HTML code.
    You can't edit HTML code.
    You can't post IFCode.
    You can't post JavaScript.
    You can post emoticons.
    You can't post or upload images.

    Select a forum

































































































































































    SQLServerCentral


    Search