Not recognize some of Emojis in sql server with Arabic_BIN collation - sql

I'm using SQL Server 2016 and my database has the Arabic_100_CI_AS collation. I inserted apple emojis in my database, but some of the emojis are equal in comparisons while other emojis are not equal. I resolved this problem with collate Arabic_BIN and I asked in this topic
But I have new problem with Arabic_BIN Collation:
For example I can't recognize some of emojis with this query:
SELECT [EMoji_ID]
FROM [Emojies].[dbo].[Emojies]
WHERE Emoji_Emoji = N'❤' COLLATE Arabic_BIN
The above query returns any ID, but this query returns ID:
SELECT [EMoji_ID]
FROM [Emojies].[dbo].[Emojies]
WHERE Emoji_Emoji = N'❤'

I solved this problem with COLLATE Arabic_100_CI_AS_SC

Related

SQL Server Collation conflict in Georgian

I have database working on Georgia server and database collation is Georgian_Modern_Sort_CI_AS so when I try to do some select on this database I cannot do select queries because of collation problem because my data include also latin alphabet unfortunately I cannot select nvarchar items.
What can I do for not getting collation error?
you can change the collation on select with using COLLATE keyword.
SELECT *
FROM MyTable
where MyLatinColumn COLLATE Georgian_Modern_Sort_CI_AS = MyGeorgianColumn

SQL query with german special char and Latin1_General_CI_AS

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

How to find rows that have a value that contains a lowercase letter

I'm looking for an SQL query that gives me all rows where ColumnX contains any lowercase letter (e.g. "1234aaaa5789"). Same for uppercase.
SELECT * FROM my_table
WHERE UPPER(some_field) != some_field
This should work with funny characters like åäöøüæï. You might need to use a language-specific utf-8 collation for the table.
SELECT * FROM my_table WHERE my_column = 'my string'
COLLATE Latin1_General_CS_AS
This would make a case sensitive search.
EDIT
As stated in kouton's comment here and tormuto's comment here whosoever faces problem with the below collation
COLLATE Latin1_General_CS_AS
should first check the default collation for their SQL server, their respective database and the column in question; and pass in the default collation with the query expression. List of collations can be found here.
SELECT * FROM Yourtable
WHERE UPPER([column_NAME]) COLLATE Latin1_General_CS_AS !=[Column_NAME]
This is how I did it for utf8 encoded table and utf8_unicode_ci column, which doesn't seem to have been posted exactly:
SELECT *
FROM table
WHERE UPPER(column) != BINARY(column)
for search all rows in lowercase
SELECT *
FROM Test
WHERE col1
LIKE '%[abcdefghijklmnopqrstuvwxyz]%'
collate Latin1_General_CS_AS
Thanks Manesh Joseph
IN MS SQL server use the COLLATE clause.
SELECT Column1
FROM Table1
WHERE Column1 COLLATE Latin1_General_CS_AS = 'casesearch'
Adding COLLATE Latin1_General_CS_AS makes the search case sensitive.
Default Collation of the SQL Server installation SQL_Latin1_General_CP1_CI_AS is not case sensitive.
To change the collation of the any column for any table permanently run following query.
ALTER TABLE Table1
ALTER COLUMN Column1 VARCHAR(20)
COLLATE Latin1_General_CS_AS
To know the collation of the column for any table run following Stored Procedure.
EXEC sp_help DatabaseName
Source : SQL SERVER – Collate – Case Sensitive SQL Query Search
I've done something like this to find out the lower cases.
SELECT *
FROM YourTable
where BINARY_CHECKSUM(lower(ColumnName)) = BINARY_CHECKSUM(ColumnName)
mysql> SELECT '1234aaaa578' REGEXP '^[a-z]';
I have to add BINARY to the ColumnX, to get result as case sensitive
SELECT * FROM MyTable WHERE BINARY(ColumnX) REGEXP '^[a-z]';
I'm not an expert on MySQL I would suggest you look at REGEXP.
SELECT * FROM MyTable WHERE ColumnX REGEXP '^[a-z]';
In Posgresql you could use ~
For example you could search for all rows that have col_a with any letter in lowercase
select * from your_table where col_a '[a-z]';
You could modify the Regex expression according your needs.
Regards,
--For Sql
SELECT *
FROM tablename
WHERE tablecolumnname LIKE '%[a-z]%';
Logically speaking Rohit's solution should have worked, but it didn't. I think SQL Management Studio messed up when trying to optimize this.
But by modifying the string before comparing them I was able to get the right results. This worked for me:
SELECT [ExternalId]
FROM [EquipmentSerialsMaster] where LOWER('0'+[ExternalId]) COLLATE Latin1_General_CS_AS != '0'+[ExternalId]
This works in Firebird SQL, it should work in any SQL queries I believe, unless the underlying connection is not case sensitive.
To find records with any lower case letters:
select * from tablename where upper(fieldname) <> fieldname
To find records with any upper case letters:
select * from tablename where lower(fieldname) <> fieldname

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 2000 DTS - Cannot resolve collation conflict for equal to operation

I have a SQL Server 2000 DTS package.
One of the steps of this package has the following SQL:
SELECT *
FROM [Crocus_Limited$OrderRequestDetail]
WHERE (rep_updated > GETDATE() -2)
AND NOT EXISTS
(SELECT OrderID
FROM NavisionUpgrade.navision4.dbo.[WEBOrderDetails] rd
WHERE rd.OrderID = [Crocus_Limited$OrderRequestDetail].OrderID
AND rd.NavisionItemNo = [Crocus_Limited$OrderRequestDetail].NavisionItemNo )
It is failing- giving me error:
cannot resolve collation conflict for equal to operation.
This DTS basically moves data from one DB to another (located in different geographical locations)
how can i alter the above query to resolve this?
One or both of your join columns has on of the char datatypes (char,nchar,varchar,nvarchar) which is stored in incompatible collations in each database.
You can specify the collation to use in any string comparison. The easiest way to do it is to specify the default collation of the machine on which the query is running (I'm guessing that NavisionItemNo is the problem column):
...AND rd.NavisionItemNo collate database_default = [Crocus_Limited$OrderRequestDetail].NavisionItemNo collate database_default )
EDIT
Is OrderID a varchar column too? If so, try
...WHERE rd.OrderID collate database_default = [Crocus_Limited$OrderRequestDetail].OrderID collate database_default
AND rd.NavisionItemNo collate database_default = [Crocus_Limited$OrderRequestDetail].NavisionItemNo ) collate database_default
as the two former posts mention you have to use the collate attribute to every nonumeric column but have a look a the collation of the target db and use this collation (e.g. SQL_Latin_CI_AS). Be aware that a table can have it's own collation even a column can have annother collation, so have a deep look in your definitions.
Peace and good luck
Ice