I have a database field with nVarchar(30). I am using asp.net MVC. When i insert the record in Unicode, i get ?????.
Any one can tell me how can i convert a string to unicode and insert into database.
I am using SQL Server 2008 R2.
Try to change your database collation to Latin1_General_BIN2.
http://msdn.microsoft.com/en-us/library/ms175835.aspx
Make sure:
You Use N' at the start of string literals containing such strings, e.g. N'enović'
If you want to query and ignore accents, then you can add a COLLATE clause to your select. E.g.:
SELECT * FROM Account
WHERE Name = 'enovic' COLLATE Latin1_General_CI_AI
Related
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 to do accent insensitive search query using SQL Server 2008 R2 and EF 6?
I need to do accent insensitive search on let's say user.name column using the Entity framework 6. I have tried to change the collation on column from default Czech_CI_AS to Czech_CI_AI. But it does not work for some Czech letters with wedges like Č, Ř, Š, Ž because the collation treats them as different letters :
http://collation-charts.org/mssql/mssql.0405.1250.Czech_CI_AI.html
I have found similar question here:
How do I perform an accent insensitive compare in SQL Server for 1250 codepage
But the proposed solution using collation Czech_100_CI_AI does not work either (for those special letters).
I have also found few sources how to do it in plain T-SQL. Like this:
SELECT *
FROM [dbo].[User]
WHERE name LIKE '%c%' COLLATE Latin1_General_CI_AI
It works fine. But I do not want to use plain SQL queries. I would like to manage it in an EF way.
I have end up with this solution:
Create view with two columns - one for the search, second for presentation (latin collation will remove some accents from the result).
CREATE VIEW [dbo].[v_UserSearch]
AS
SELECT
dbo.[User].name AS FirstName,
dbo.[User].name COLLATE Latin1_General_CI_AI AS FirstNameCI
FROM dbo.[User]
Create DB mapping for the view in EF context.
Use the FirstNameCI column for the search in EF.
if (!string.IsNullOrWhiteSpace(filter.FirstName))
query = query.Where(x => x.c.FirstNameCI.StartsWith(filter.FirstName));
Use the FirstName column for presentation.
In Entity Framework, when you use Contains() method in where() extension method in IQueryable, it is translated to where clause with like operator in SQL. So I guess this is what are you looking for. You can refer to this SO question.
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.
I have bulk-data in SQL-Server table. One of the fields contains following data :
'(اے انسان!) کیا تو نہیں جانتا)'
Tried:
SELECT * from Ayyat where Data like '%انسان%' ;
but it is showing no-result.
Plese use N before string if language is not a english:
SELECT * from Ayyat where Data like N'%انسان%' ;
If you're storing urdu, arabic or other language except english in your database first you should convert your database into another format and then also table.
first you've to convert your database charset and also collation alter your database
ALTER DATABASE database_name CHARACTER SET utf8 COLLATE utf8_general_ci
then convert your table
ALTER TABLE table_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci
after this execute normal your query
SELECT * FROM table_name WHERE Datas LIKE '%انسان%'
Note: if you not convert your database and table other languages and special characters will be changed into question marks.
I am running a SQL Server 2008 R2 and I have a database containing multilingual words.
For Cyrillic words I only see '???????'
The data type is nvarchar(255), the collection is SQL_Latin1_General_CP1_CI_AS (which was my default)
I have no idea what else can I do, any idea??
When you add data to the nvarchar column, use the prefix N
Insert into table(nvarchar_col)
select N'your Cyrillic words'