Avatar of ebram ishaak
ebram ishaak
Flag for Egypt asked on

data stored like ????? in sql server nvarchar column

CREATE SCHEMA Product;

CREATE TABLE [Product].[ProductCategory]
(
 ID INT IDENTITY(1,1) PRIMARY KEY,
 Name NVARCHAR(20) NOT NULL UNIQUE,

 CONSTRAINT C_ProductCategoryName CHECK
 ((LEN([Name])BETWEEN 1 AND 20) AND ([Name]+'.'<>'.') AND ([Name] NOT LIKE' %') AND ([Name]NOT LIKE'% '))
);

CREATE PROC [Product].[SP_AddProductCategory]
(@Name NVARCHAR(20))
AS
BEGIN
            INSERT INTO [Product].[ProductCategory] VALUES (@Name)
END

EXEC [Product].[SP_AddProductCategory] 'T-shirt' -----result--> T-shirt
EXEC [Product].[SP_AddProductCategory] 'تيشيرت' -----result--> ??????

i want to add N prefix in stored procedure to be able to stored arabic values successfully when exec the stored procedure
Microsoft SQL Server

Avatar of undefined
Last Comment
Vitor Montalvão

8/22/2022 - Mon
Vitor Montalvão

Try:
EXEC [Product].[SP_AddProductCategory] N'تيشيرت'

Open in new window

ebram ishaak

ASKER
MR Vitor
i want to solve it inside the procedure not while execution
something like @Name=N+@Name
so when execute it's not nessesary to put N prefix
Vitor Montalvão

Does the column has an Arabic collation?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ebram ishaak

ASKER
database collation is (sql_latin_general_cp1_ci_as)
i didnot bound any coulmn with any collation so column collation should be (sql_latin_general_cp1_ci_as) and it's datatype is Nvarchar
ASKER CERTIFIED SOLUTION
Vitor Montalvão

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ebram ishaak

ASKER
MR Vitor
so what is acollation that supports arabic and english to bound the column with and is there a collation can bound to column to support any language?
thank you
SOLUTION
Vitor Montalvão

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ebram ishaak

ASKER
MR\Vitor

in my case user can store arabic or english values in the same column actually in the same field
i want in my stored procedures take parameters whatever arabic or english and execute successfully without n prefix in my
execute statements my database collation is (sql_latin_general_cp1_ci_as) i created this columns in Nvarchar
my question is (is (sql_latin_general_cp1_ci_as) can support arabic and english?)
-if yes, why data stored like ????? when store arabic
-if no,when i tried to change database colltion to Arabic_CI_AS give me the following error
error.JPG
what can i do in steps please?
thanks
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Vitor Montalvão

in my case user can store arabic or english values in the same column actually in the same field
Please let me know how are you doing this, because I never saw a case where that's possible.

my question is (is (sql_latin_general_cp1_ci_as) can support arabic and english?)
No it can't. Can support all occidental languages as English, German, Spanish, French, Italian, Portuguese, Swedish, etc... but not oriental languages as Arabic, Chinese, Japanese, Korean, ...

-if yes, why data stored like ????? when store arabic
That's a proof that it can't store Arabic characters.

-if no,when i tried to change database colltion to Arabic_CI_AS give me the following error
That's because Arabic collation isn't compatible with Latin_General collation so SQL Server can't perform the necessary conversion.

With all that said I still keep my suggestion:
"What you can do is to create another column only for Arabic and keep the current one for Occidental languages. "
ebram ishaak

ASKER
arabic and english can be together in the same column and in the same field
below is a picture for an example database but this database collation is Arabic_CI_AS
arabic-and-english-together.JPGbut my problem is my original database created with latin collation and i want my Nvarchar columns store data like previous example
Vitor Montalvão

What is the collation for the EXPERT3 database? And for t1 table and Name column? I don't think they are a sql_latin_general collation, right?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ebram ishaak

ASKER
MR\Vitor

EXPERT3 is in Arabic_CI_AS and i didn't bound any table or column with a collation so table took the database collation.
the problem is my original database collation is Sql latin general and all it's tables and columns and when i tried to change database collation to arabic error occur and when i tried to change column collation arabic doesn't exists in drop down list to choose from table design.
you think the only solution is to create a new database with arabic collation and execute original database script to it or there is a solution ?

thanks
SOLUTION
Vitor Montalvão

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ebram ishaak

ASKER
error.JPG
SOLUTION
Vitor Montalvão

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ebram ishaak

ASKER
no i execute only the alter statement and it gives me the error but  now i dropped the table and recreate it as
CREATE TABLE [Product].[ProductCategory]
 (
  ID INT IDENTITY(1,1) PRIMARY KEY,
  Name NVARCHAR(20) COLLATE Arabic_CI_AS NOT NULL UNIQUE,

  CONSTRAINT C_ProductCategoryName CHECK
  ((LEN([Name])BETWEEN 1 AND 20) AND ([Name]+'.'<>'.') AND ([Name] NOT LIKE' %') AND ([Name]NOT LIKE'% '))
 );
and it execute successfully
but the error still exists !!!!!!!!
error.JPG
there is no way to change the collation of database i think this may help ,
i want to thank you mr vitor for your great help and efforts
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Vitor Montalvão

You're not sending the parameter with N for nvarchar:
EXEC [Product].[SP_AddProductCategory] N'تيشيرت' 

Open in new window

Vitor Montalvão

ebram ishaak, is this issue solved or do you still have questions about it?
Vitor Montalvão

Recommendation to close this question by accepting the above comments as solution.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes