SQL query with german special char and Latin1_General_CI_AS - sql

I am trying to read some entries out of a microsoft sql database.
The problem ist, that one of the columns has a name with special characters "bedürfnisse" and the entries are all in Latin1_General_CI_AS.
I need to select this column.
Select nameName.bedürfnisse
FROM nameName
This is not working. I also tried
Select nameName.bedürfnisse COLLATE Latin1_General_CI_AS
FROM nameName
but this is also not working. How can i select this column?

You need to escape your column names if they contain special characters. This also includes whitespace or other non-standard ascii characters in column names.
For standard ANSI SQL the syntax to do this is:
SELECT nameName."bedürfnisse"
FROM nameName
For SQL Server this also works:
SELECT nameName.[bedürfnisse]
FROM nameName
For MySQL, this also works:
SELECT nameName.`bedürfnisse`
FROM nameName

What really helped was to define UTF-8 in the connection. Its one of the option parameter

Related

how to retrieve sql column includes special characters and alphabets

How to retrieve a column containing special characters including alphabets in SQL Query. i have a column like this 'abc%def'. i want to retrieve '%' based columns from that table.
Please help me in this regard.
Is abc%def the column name? or column value? Not sure what you are asking but if you mean your column name contains special character then you can escape them which would be different based on specific RDBMS you are using
SQL Server use []
select [abc%def] from tab
MySQL use backquote
select `abc%def` from tab
EDIT:
Try like below to fetch column value containing % character (Checked, it works in Ingres as well)
select * from tab where col like '%%%'
Others suggest that like '%%%' works in Ingres. So this is something special in Ingres. It does not work in other dbms.
In standard SQL you would have to declare an escape character. I think this should work in Ingres, too.
select * from mytable where str like '%!%%' escape '!';

Replace Ambigious / Invalid Text Characters from String

I am inserting the string into table. But there are some ambiguous, illegal text characters like 'ÔÇô' , '├®' appearing in the string. I want to replace all these invalid characters from the table and update my table. Is there any way to replace such characters in SQL. I am using SQL server 2008.
You could use one of the functions here:
How to strip all non-alphabetic characters from string in SQL Server?
You haven't included your insert statement, so I'm going to guess you've done it similar to
insert into table2
SELECT dbo.fn_StripCharacters(myfield1, 'a-z0-9'), myfield2, myfield3 from table1
Like you said... "Replace".
Replace documentation
Hint: Replace the ambigous character with an empty string.
Also you can go for nvarchar, nchar or ntext to support these unicode chars in case you need those. If its really needs to replace the yous hould go for Replace() of Sql Server

Unicode characters in Sql table

I am using Sql Server 2008 R2 Enterprise. I am coding an application capable of inserting, updating, deleting and selecting records from a Sql tables. The application is making errors when it comes to the records that contain special characters such as ć, č š, đ and ž.
Here's what happens:
The command:
INSERT INTO Account (Name, Person)
VALUES ('Boris Borenović', 'True')
WHERE Id = '1'
inserts a new record but the Name field is Boris Borenovic, so character ć is changed to c.
The command:
SELECT * FROM Account
WHERE Name = 'Boris Borenović'
returns the correct record, so again the character ć is replaced by c and the record is returned.
Questions:
Is it possible to make Sql Server save the ć and other special characters mentioned earlier?
Is it still possible, if the previous question is resolved, to make Sql be able to return the Boris Borenović record even if the query asks for Boris Borenovic?
So, when saving records I want Sql to save exactly what is given, but when retrieving the records, I want it to be able to ingnore the special characters. Thanks for all the help.
1) Make sure the column is of type nvarchar rather than varchar (or nchar for char)
2) Use N' at the start of string literals containing such strings, e.g. N'Boris Borenović'
3) If you're using a client library (e.g. ADO.Net), it should handle Unicode text, so long as, again, the parameters are marked as being nvarchar/nchar instead of varchar/char
4) 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 = 'Boris Borenovic' COLLATE Latin1_General_CI_AI
Where _CI_AI means Case Insensitive, Accent Insensitive, should return all rows with all variants of the "c" at the end.
5) If the column in the table is part of a UNIQUE/PK constraint, and you need it to contain both "Boris Borenović" and "Boris Borenovic", then add a COLLATE clause to the column definition, but this time use a collation with "_AS" at the end, which says that it's accent sensitive.
To allow SQL Server to store special characters, use nvarchar instead of varchar for the column type.
When retrieving, you can force a accent-insensitve collation so that it ignores the different C's:
WHERE Name = 'Boris Borenović' COLLATE Cyrillic_General_CI_AI
Here, CI stands for Case Insensitive, and AS for Accent Insensitive.
I've faced with the same problem and after some researching:
https://dba.stackexchange.com/questions/139551/how-do-i-set-a-sql-server-unicode-nvarchar-string-to-an-emoji-or-supplementary
What is the difference between varchar and nvarchar?
I altered type of needed fields:
ALTER TABLE [table_name] ALTER COLUMN column_name [nvarchar]
GO
And it works!

SQL LIKE with special characters

If I try to create a select with special (nordic) characters like:
Select * from users where name like '%æ%'
It just selects all users instead of those containing the letter 'æ'.
Do I need to install some special drivers to the database, or is there something else I have missed?
Update:
I am using a SQL Server 2008 database, the collation is set to 'SQL_Latin1_General_CP1_CI_AS' and the datafield is a nullable nVarChar datatype.
Most likely some collation or datatype issue
Example, gives 97 and 230
SELECT ASCII('æ' COLLATE Albanian_CI_AI), ASCII('æ' COLLATE Latin1_General_CI_AS)
We'll need more info basically.
Edit: Question about Danish/Norwegian å (although unresolved)
Edit 2: change the code to this if name is nvarchar so the literal becomes unicode too.
Select * from users where name like N'%æ%'
Make sure you're using an extended character set (UTF-8) and you should be fine.
it should be work correctly ..
but try this Select * from users where name like '%[æ]%'

SQL Server - Searching string with international characters using LIKE clause

I have a field 'Description' which can have product descriptions with any unicode characters.
If I search for a description which contains an international character, with a LIKE condition (word searched with does not have the international character) I get the following results:
Ex: GEWÜRZTRAMINER is one of the descriptions.
When I do:
Select * from table where Description LIKE '%GEWURZTRAMINER%', it retrieves the entry.
When I do:
Select * from table where Description LIKE '%GEWURZ%', the entry is not retrieved.
(Note: the search condition does not include the Ü but has a U)
Is there a way around this so that I can retrieve with '%GEWURZ%' as well?
For bog standard varchar, you'd have to coerce to a accent insensitive collation
Select 1 where 'GEWÜRZTRAMINER' COLLATE LATIN1_GENERAL_CI_AI LIKE '%GEWURZTRAMINER%'
There should be no difference between the calls though for the SQL you provided.
It will depend on the collation order for the column. It should work if you use e.g. SQL_Latin1_General_CP1_CI_AI