Search code examples
c#sql-serversave

Problem inserting a Persian character between two numbers for save in SQL Server


Actually, I want to save the license plate with Persian characters as below.

Example:

"12 (Persian Character) 423" 
//First, two digits, then a Persian character followed by three digits.

But the problem is stored in SQL Server as shown below:

enter image description here

Data type for plaque:

enter image description here

What needs to be done in order I want to save and then read it?


Solution

  • Looking to save Unicode? Use the N prefix: INSERT INTO YourTable(yourcolumn) VALUES (N'yourstring')

    Update: Trickery to store the value without getting reversed:

    Create Table #tbl
    (
    val nVarChar(25)
    )
    
    insert into #tbl select Reverse((Reverse(N'12')+N'ص' + Reverse(N'423'))) 
    
    Select * From #tbl
    

    Result