1

I am trying to insert some information in Arabic from a XML variable into a SQL Server table.

I did something like the below. However it does not work. Could you please tell what is missing?

Create Table EmployeeTbl
(
     firstname nvarchar(100), 
     familyName nvarchar(100) 
)

Insert into EmployeeTbl (firstName, FamilyName) 
    select 
        t.x.value('(./firstname)[1]', 'nvarchar(100)') as firstname,
        t.x.value('(./familyname)[1]', 'nvarchar(100)') as familyname           
    from  
        @XMLVariable.nodes('//employeexml) t(x) 
XAMT
  • 1,515
  • 2
  • 11
  • 31

1 Answers1

0

Yes, You missed a single-quotes(') at last line:

Create Table EmployeeTbl
(
     firstname nvarchar(100), 
     familyName nvarchar(100) 
)

Insert into EmployeeTbl (firstName, FamilyName) 
    select 
        t.x.value('(./firstname)[1]', 'nvarchar(100)') as firstname,
        t.x.value('(./familyname)[1]', 'nvarchar(100)') as familyname           
    from  
        @XMLVariable.nodes('//employeexml') t(x)

Your XML file should be like that :

<employeexml Id="1">  
     <firstname>بشیر</firstname>  
     <familyname>المنادی</familyname>  
</employeexml>
<employeexml Id="2">  
     <firstname>یعغوب</firstname>  
     <familyname>سمیر</familyname>  
</employeexml>
XAMT
  • 1,515
  • 2
  • 11
  • 31
  • 1
    *"You missed a single-Colon at last line"* your code contains no semi colon (`;`), if that's what you meant, either. Not that they are compulsary in T-SQL (yet). If this was, however, a typographical error, then you should flag it as such. – Thom A Feb 02 '20 at 20:54
  • Sorry, I mean Single quotes('). Thanks, @Larnu. You are my lifesaver. – XAMT Feb 02 '20 at 21:00
  • If that *is* the reason, then this is purely a typographical error. – Thom A Feb 02 '20 at 21:01
  • What do you mean? Are you asking how to use markdown in comments? The same way you do in posts. You just can't do things like block code and block quotes. – Thom A Feb 02 '20 at 21:10
  • Sorry for the late reply due to time difference. Yes the XML looks like the one that is posted by XAMT. The XML is passed as a variable to a store procedure where the insert into table statement is called. The problem is that values are inserted as ??????? in the columns. We need to store the values in Arabic as they are coming in the XML. That's the problem. – Bilal Bakri Feb 03 '20 at 07:59
  • @BilalBakri; Nope, You have a Typo: `('//employeexml)` . It should be: `('//employeexml')` – XAMT Feb 03 '20 at 08:05