سؤال

I need to write a sql script that will create a table in the database and populate it with data from the file type Resources.resx

As far as I can see, there are only 3 fields: Name, Value and Comment. All string.

I using Microsoft SQL Server (Management Studio)

<data name="Filter" xml:space="preserve">
<value>Фильтры</value></data>
هل كانت مفيدة؟

المحلول

Try this one -

DECLARE @XML XML
SELECT @XML = '
<data name="Filter" xml:space="preserve">
     <value>Фильтры</value>
</data>'

CREATE TABLE dbo.translations
(
      name VARCHAR(100)
    , value NVARCHAR(200)
)

INSERT INTO dbo.translations (name, value)
SELECT 
       name = t.c.value('@name', 'VARCHAR(100)')
     , value = t.c.value('./value[1]', 'NVARCHAR(200)')
FROM @XML.nodes('data') t(c)

SELECT * 
FROM dbo.translations 

Output -

name       value
---------- ----------
Filter     Фильтры
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top