Bonjour à tous,
Je cherche à faire un SELECT sur un champ XML de ma table mais je bloque sur un point.
SGBD: SQL Server
Mon XML:
Le noeud <PageAnnotations> peut se répéter X fois.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 <SectionAnnotations xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SectionNumber>0</SectionNumber> <Pages> <PageAnnotations> <PageNumber>2</PageNumber> <Annotations> <Layer xmlns="http://test" Id="1234"> <TextStamp Transparent="true" Id="1" UserName="dwadmin"> <Created User="dwadmin" Time="2022-09-23T15:10:02Z" /> <Location Left="7085" Top="831" Width="1980" Height="886" /> <HeadFont FontName="Arial" FontSize="220" /> <Font FontName="Arial" FontSize="220" /> <Value>X</Value> </TextStamp> </Layer> </Annotations> </PageAnnotations> <PageAnnotations> <PageNumber>4</PageNumber> <Annotations> <Layer xmlns="http://test" Id="1234"> <TextStamp Transparent="true" Id="1" UserName="dwadmin"> <Created User="dwadmin" Time="2022-09-23T15:10:02Z" /> <Location Left="7085" Top="831" Width="1980" Height="886" /> <HeadFont FontName="Arial" FontSize="220" /> <Font FontName="Arial" FontSize="220" /> <Value>X</Value> </TextStamp> </Layer> </Annotations> </PageAnnotations> <PageAnnotations> <PageNumber>8</PageNumber> <Annotations> <Layer xmlns="http://test" Id="1234"> <TextStamp Transparent="true" Id="2" ShowUser="false" ShowDate="false" ShowTime="false"> <Created User="dwadmin" Time="2022-09-23T15:11:23Z" /> <Location Left="4498" Top="1488" Width="5216" Height="353" /> <HeadFont FontName="Arial" FontSize="220" /> <Font FontName="Arial" FontSize="220" /> <Value>Y</Value> </TextStamp> </Layer> </Annotations> </PageAnnotations> </Pages> </SectionAnnotations>
Je dois récupérer les valeurs de PageNumber si l'ID dans TextStamp est égal à 1.
Dans le cas où j'ai plusieurs noeud avecdes ID TextStamp à 1 je dois récupérer toutes les valeurs de PageNumber en les concaténant (séparation avec une virgule).
J'arrive facilement à récupérer la 1ere valeur de PageNumber avec:
Mais je vois pas comment boucler sur un champ XML ni comment faire la concaténation si plusieurs valeurs.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 SELECT MONCHAMPXML.value('(/SectionAnnotations//PageNumber/node())[1]', 'nvarchar(max)') as PageNumber FROM MaTable
Des pistes à me proposer?
Merci pour votre aide,
Partager