I try to get all the fields name from a form stored as XML in SQL Server, based on the value of an attribute (Culture). Actually, I can get the text value, but they are concatenated into the FieldName column.
XML structure looks like this:
<Form>
<Field>
<Field Name="email" Type="text" ColumnSize="6">
<Localizations>
<Localization Culture="fr">
<Text>Adresse couriel</Text>
<Placeholder>Entrez votre adresse courriel</Placeholder>
</Localization>
<Localization Culture="fr">
<Text>Email</Text>
<Placeholder>Enter your email</Placeholder>
</Localization>
</Localizations>
</Field>
</Fields>
</Form>
SQL Query:
DECLARE @language VARCHAR(2)
SET @language = 'en'
SELECT
c.query('data(@Name)') AS FieldUniqueName,
c.query('data(./Localizations/Localization/Text)') AS FieldName,
c.query('data(@Type)') AS FieldType
FROM dbo.Form Form CROSS APPLY FormContent.nodes('/Form/Fields/Field') x(c)
WHERE Id = @formId
AND FormContent.exist('/Form/Fields/Field/Localizations/Localization[@Culture=sql:variable("@language")]') = 1
Result look like this :
FieldUniqueName | FieldName | FieldType
name | Nom Name | text
email | Adresse couriel Email | text
phone | Téléphone Phone Number| text
Both languages are in the FieldName column!
I have tried also with :
...
c.value('data(./Localizations/Localization/Text)[1]', 'VARCHAR(100)') AS FieldName,
...
But I need to choose between [1]
or [2]
to get the right language...