Sybase SQL using French character - sql

I have a local Sybase database. This is a dbf file on my computer. This Sybase database holds string values with French characters, like "é".
The problem I have is that I can not find any values that have a "é" character in the string.
The values are present in the table. I know this, because when I do not apply any restriction and select all records, I can see the values that hold an "é" character in their strings.
Example:
Select Column from SybasteTable
where Column = 'Fench é letters'
If I apply this restrictions, no records can be found even though records exists for this column.

Your question is not entirely clear to me. But if I am not mistaken you are looking for a way to select all rows with the é char inside it.
IF that is the case try this query
SELECT [columnName] FROM [tableName]
WHERE [columName] SIMILAR TO '[a-e]'
Where [columnName] is the name of your column and [tableName] the name of your table
If I misunderstood your question, and you are looking for something else. could you please clarify your question or rephrase it.
EDIT:
replaced like clause with SIMILAR TO which should get all the accented chars between and including a - e.

Related

Sql LIKE in Arabic?

Consider this sample:
CREATE TABLE #tempTable
(name nvarchar(MAX))
INSERT INTO #tempTable VALUES (N'إِبْرَاهِيمُ'), (N'إبراهيم')
SELECT * FROM #tempTable WHERE name = N'إبراهيم'
SELECT * FROM #tempTable WHERE name LIKE N'%إبراهيم%'
Both selects only return إبراهيم but not إِبْرَاهِيمُ. How can I make it ignore these non-alphabetical characters in search? In other words, I want to get all similar words, including those with non-alpha characters.
You do not do it. Simple. NOTHING about arabic here - you have the same problem in english.
How can I make it ignore these non-alphabetical characters in search?
Like numbers? NOT AT ALL. Not with "standard SQL Syntax".
If you can, put a full text index on the field. And use the full text search syntax in your query. This is what it is for.
There is a thread over at sql stackexchange that has a workaround for this issue.
https://dba.stackexchange.com/questions/14153/treating-certain-arabic-characters-as-identical
Unfortunately, there is no case sensitive Arabic language, and of course, both select statements will return 'إبراهيم' because they were ordered to do that.
This is a problem we have been suffering from for a very long time, people always look for 'احمد' when it's written 'أحمد' and they won't find it.
this is a solution 100%:
$yourChaine = \Transliterator::create('NFC; [:Nonspacing Mark:] Remove; NFC')
->transliterate($yourChaine);

Regex to get data with special characters

I have some data in my table's column upn.
Here is a small sample set of this data.
Pasquale.Rombolà#it.eurw.domain.net
JuanMaria.RomanGonçalves#eurs.domain.net
Santo.Paternò#it.eurw.domain.net
Peter.Browne#UK.EURW.domain.net
François.ESTIN#fr.eurw.domain.net
Frédéric.Huynh#fr.eurw.domain.net
Frédérique.Psaume#fr.eurw.domain.net
Laura.PiñeiroGomez#eurs.domain.net
Maria.AranzabalSaldaña#eurs.domain.net
Alberto.RubioMuñoz#eurs.domain.net
Peter.Brüggemann#UK.EURW.domain.net
Russel.Peters#CA.domain.net
I want to query this table for UPN values where I have some special characters in the UPN. So my query should not return upns such as:
Peter.Browne#UK.EURW.domain.net
and
Russel.Peters#CA.domain.net
But returns everything else with special characters such as [à,ò,ñ,ü ...etc]
I have tried this query but it doesn't work.
Select * from TableName
Where [UPN] like %[a-z,0-9,#,\.,-,A-Z]%
It returns everything including those which don't have any special characters.
Please help.
If I understand correctly, I think you'll just need to add a "^" as the first character inside the square brackets.
At present you're saying you want to return all those UPNs where one or more characters is in the list you give (i.e. the "ordinary" characters). The "^" should reverse that and give you all the UPNs where at least one of the characters is not in the list you give.
Update: After testing locally ... Make sure your collation is "Accent Sensitive" (if necessary add "Latin1_General_CI_AS" or similar after your "like" clause.
I found it only worked if rather than "A-Z", I actually typed out the whole alphabet.
You need to add binary collate clause in it. Chose necessary collation as per your data. For given sample data Latin1_General_BIN works. Here is the link for collation in sql server.
This snippet worked for me on my machine-
create table #t (name varchar(100));
insert into #t values
('Pasquale.Rombolà#it.eurw.domain.net'),
('JuanMaria.RomanGonçalves#eurs.domain.net'),
('Santo.Paternò#it.eurw.domain.net'),
('Peter.Browne#UK.EURW.domain.net'),
('François.ESTIN#fr.eurw.domain.net'),
('Frédéric.Huynh#fr.eurw.domain.net'),
('Frédérique.Psaume#fr.eurw.domain.net'),
('Laura.PiñeiroGomez#eurs.domain.net'),
('Maria.AranzabalSaldaña#eurs.domain.net'),
('Alberto.RubioMuñoz#eurs.domain.net'),
('Peter.Brüggemann#UK.EURW.domain.net'),
('Russel.Peters#CA.domain.net');
select * from #t where name not like '%[^a-zA-Z0-9#.]%' COLLATE Latin1_General_BIN;
Output-
Peter.Browne#UK.EURW.domain.net
Russel.Peters#CA.domain.net

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 '!';

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!

Replace NOT working!

I have column with values that have wrong character ?. Now I want to change it to character b. For this I am using this statement:
SELECT REPLACE(name,'?','b') from contacts;
But when I do this nothing's happening, it return value with ?.
What I am doing wrong? How I can replace this?
Are you actually trying to change the values in the table? In that case, you'll need to do an UPDATE:
UPDATE contacts
SET name = Replace(name,'?','b')
Otherwise, if you are simply trying to retrieve a modified value, your syntax should work just fine. (I tested it, ? doesn't have to be escaped or anything):
SELECT name, Replace(name,'?','b') as Fixed
FROM contacts
Another possibility that I've seen before is that the character looks like a regular old ASCII question mark but it's not really. It's actually a different character. I'd select the text and paste it into Notepad and then copy and paste it into my query.
If your name column data type is NVARCHAR you should use N prefix. NVARCHAR and VARCHAR types have unicode differance. Look at this link for more information about differance between NVARCHAR and VARCHAR types.
SELECT REPLACE(name,N'?', N'b') from contacts;
Try this
update contacts set name=replace(name, '?', 'b')