Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.databases.ms-sqlserver > #1670
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Erland Sommarskog <esquel@sommarskog.se> |
| Newsgroups | comp.databases.ms-sqlserver |
| Subject | Re: Get XML values from nodes and child nodes |
| Date | Mon, 10 Feb 2014 23:45:13 +0100 |
| Organization | Erland Sommarskog |
| Lines | 50 |
| Message-ID | <XnsA2D0F1A2835A1Yazorman@127.0.0.1> (permalink) |
| References | <0a2e63e1-d6c0-4493-b52b-2d60a50bf1b7@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252 |
| Content-Transfer-Encoding | 8bit |
| Injection-Info | mx05.eternal-september.org; posting-host="fd3d6d0229f14a752f017d8f9903addd"; logging-data="17654"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+a1d18Q6zljr02D5jbtfFy" |
| User-Agent | Xnews/2006.08.24 Mime-proxy/2.1.c.0 (Win32) |
| Cancel-Lock | sha1:RJG0lEqTn0LW78JtU64yPzZ5Hns= |
| Xref | csiph.com comp.databases.ms-sqlserver:1670 |
Show key headers only | View raw
(giancarlo.francesconi@gmail.com) writes:
> I only get the first node values (NumeroProgressivo, CodiceFiscale), but
> not the child nodes (cognome, nome sesso...)
>
DECLARE @xml xml =
'<Locatore>
<NumeroProgressivo>001</NumeroProgressivo>
<CodiceFiscale>CSTNDA69P90H523R</CodiceFiscale>
<PersoneFisiche>
<Cognome>CAST</Cognome>
<Nome>NADIR</Nome>
<Sesso>F</Sesso>
<DataNascita>10091979</DataNascita>
<ComuneNascita>RONCA</ComuneNascita>
<ProvinciaNascita>BL</ProvinciaNascita>
</PersoneFisiche>
</Locatore>
<Locatore>
<NumeroProgressivo>002</NumeroProgressivo>
<CodiceFiscale>PRSGRI74L29F443L</CodiceFiscale>
<PersoneFisiche>
<Cognome>PERISSI</Cognome>
<Nome>IGOR</Nome>
<Sesso>M</Sesso>
<DataNascita>29071970</DataNascita>
<ComuneNascita>MONTE</ComuneNascita>
<ProvinciaNascita>SA</ProvinciaNascita>
</PersoneFisiche>
</Locatore>'
SELECT
X.valore.query('NumeroProgressivo').value('.', 'VARCHAR(20)') as
NumeroProgressivo,
X.valore.query('CodiceFiscale').value('.', 'VARCHAR(16)') as CodiceFiscale ,
Y.valore.query('Cognome').value('.', 'VARCHAR(16)') as Cognome,
Y.valore.query('Nome').value('.', 'VARCHAR(16)') as Nome,
Y.valore.query('Sesso').value('.', 'VARCHAR(16)') as Sesso,
Y.valore.query('DataNascita').value('.', 'VARCHAR(8)') as DataNascita,
Y.valore.query('ComuneNascita').value('.', 'VARCHAR(16)') as ComuneNascita,
Y.valore.query('ProvinciaNascita').value('.', 'VARCHAR(16)') as
ProvinciaNascita
FROM @xml.nodes('/Locatore') AS X(valore)
CROSS APPLY X.valore.nodes('PersoneFisiche') AS Y(valore)
--
Erland Sommarskog, Stockholm, esquel@sommarskog.se
Back to comp.databases.ms-sqlserver | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Get XML values from nodes and child nodes giancarlo.francesconi@gmail.com - 2014-02-10 02:20 -0800 Re: Get XML values from nodes and child nodes Erland Sommarskog <esquel@sommarskog.se> - 2014-02-10 23:45 +0100 Re: Get XML values from nodes and child nodes Bal Govind <balgovindjss@gmail.com> - 2014-03-11 05:28 -0700
csiph-web