SQL Server: Replace Arabic Character in Select Statement - sql-server

I would like to replace Arabic character in select statement with another Arabic character in SQL server, example query:
select replace(ArabicName, 'أ', 'ا') as ArabicName from dataIndividual;
But it does not replace, the reason probably that SQL server does not read the character as Unicode but as ASCII (I guess).
Is there a way to pass a Unicode characters for replace function?
Note: I already tried collate after the Arabic character.

Prefix your string with N
select replace(ArabicName, N'أ' , N'ا') as ArabicName
from dataIndividual;

Related

How to idetify the phonetic alphabets in MS SQL database tables

We have inserted more than 100000 records through Import flat file functionality in sql server management studio. It was inserted successfully.
But some of column values contained characters like é and ö .
It got converted into while storing in sql column for all above characters like(ö,é).
Moreover the below SQL statements is not giving any results.
select * from Temp where column1 like '%%'
The data with these characters in the tables are being displayed with a symbol(question mark in a diamond).
Please help as to how can I insert the data keeping the phoentic symobols intact.
Your data contains some characters like é and ö. But when you see in the database, it's stored "?" instead of that, right?
I think, your database does not support all characters. I would recommend to change it to something like this:
character set: utf8
collation: utf8_general_ci
Hope to help, my friend :))
character set: utf8
collation: utf8_general_ci
SELECT
*
FROM TEMP
WHERE SOUNDEX(COLUMN1) LIKE SOUNDEX('A')
strong text

How do you get the Unicode code of a character in a SQL Server database table?

I've been given a string of characters in a SQL Server DB table, in a column of datatype nvarchar(510). I'm trying to get the Unicode code of the first character in the string using this SQL:
select unicode(substring(asciicharacter, 1, 1))
from TableAscii;
but no matter what the character is, the select returns "1". What am I doing wrong?

SQL Server replace function has odd behavior with unicode modifier character

I have data with some half-width unicode characters in it (specifically U+FF9F) which seem to be interfering with the replace function:
select replace(convert(nvarchar(max), N'"'), N'"', N'""')
returns "" as expected, but
select replace(convert(nvarchar(max), N'"゚'), N'"', N'""')
returns the input string unaffected: "゚. I believe this is due to SQL Server interpreting the two-character sequence as being distinct from " by itself.
Is there any way to get the replace function to replace that double-quotation character with two?
EDIT: This question is slightly different from the answer posed in Replacing a specific Unicode Character in MS SQL Server. That question is asking about removing a half-width character, while this question is about modifying a character next to a half-width character. In both questions it was needed to set the collation to Latin1_General_BIN
Use COLLATE Latin1_General_BIN to work on Unicode characters.
SELECT REPLACE(CONVERT(nvarchar(max), N'"゚') COLLATE Latin1_General_BIN, N'"', N'""')

Insert persian characters in SQL database

I am trying to insert Ḩāfiz̧ Moghul into a SQL database column with nvarchar(100) set as the datatype.
For some reason it is replacing the first letter with a ?
How do I fix this?
If you want to insert Unicode characters as string literals in a SQL statement, you must prefix the string with a N character:
INSERT INTO dbo.YourTable(UnicodeColum)
VALUES (N'Ḩāfiz̧ Moghul');
If you omit the N prefix, the string will be converted to non-Unicode Varchar before being inserted.

Why can I store an Ukrainian string in a varchar column?

I got a little surprised as I was able to store an Ukrainian string in a varchar column .
My table is:
create table delete_collation
(
text1 varchar(100) collate SQL_Ukrainian_CP1251_CI_AS
)
and using this query I am able to insert:
insert into delete_collation
values(N'використовується для вирішення квитки')
but when I am removing 'N' it is showing ?????? in the select statement.
Is it okay or am I missing something in understanding unicode and non-unicode with collate?
From MSDN:
Prefix Unicode character string constants with the letter N. Without
the N prefix, the string is converted to the default code page of the
database. This default code page may not recognize certain characters.
UPDATE:
Please see a similar questions::
What is the meaning of the prefix N in T-SQL statements?
Cyrillic symbols in SQL code are not correctly after insert
sql server 2012 express do not understand Russian letters
To expand on MegaTron's answer:
Using collate SQL_Ukrainian_CP1251_CI_AS, SQL server is able to store ukrainian characters in a varchar column by using CodePage 1251.
However, when you specify a string without the N prefix, that string will be converted to the default non-unicode codepage before it is sent to the database, and that is why you see ??????.
So it is completely fine to use varchar and collate as you do, but you must always include the N prefix when sending strings to the database, to avoid the intermediate conversion to default (non-ukrainian) codepage.

Resources