SELECT query with greek characters - sql

I have a table that contains a VARCHAR row with latin_sweedish_ci collation. I want to select-like query with greek characters inside. My query is the following:
$sql="SELECT * FROM ekptes WHERE eponimo LIKE Ν '%$a%' ";
The $a variable has a UTF-8 greek character encoding. How I can solve this query?

Your column is collated with swedish, not greek.
Make an ALTER over this table and/or column(s). Than greek characters will work correctly.

Related

How to write the LIKE syntax where the search term includes a percentage (%)?

I am using SQL Server 2012 and I need to perform a search on a specific field, called Notes. The search criteria is to find all rows where the term 8% is mentioned in that specific field.
The WHERE clause of my T-SQL query looks like this:
WHERE [Notes] like '%[8%]%'
However, the query is not filtering correctly based on the above syntax. It is also including rows where the term 8 is mentioned.
I had a look at the answers proposed in the question below, but they are still not giving me the correct answer.
SQL 'LIKE' query using '%' where the search criteria contains '%'
A single character class represents a single character. So [%] means a literal percent symbol, and 8[%] means literal 8%. Try this:
SELECT * FROM yourTable WHERE [Notes] like '%8[%]%'
Demo
you need to escape % in query for example below
SELECT columns FROM table
WHERE column LIKE '%\%%' ESCAPE '\'
Using SQL Escape Sequences
Below is from MSDN
Pattern Matching with the ESCAPE Clause
You can search for character strings that include one or more of the special wildcard characters. For example, the discounts table in a customers database may store discount values that include a percent sign (%). To search for the percent sign as a character instead of as a wildcard character, the ESCAPE keyword and escape character must be provided. For example, a sample database contains a column named comment that contains the text 30%. To search for any rows that contain the string 30% anywhere in the comment column, specify a WHERE clause such as WHERE comment LIKE '%30!%%' ESCAPE '!'. If ESCAPE and the escape character are not specified, the Database Engine returns any rows with the string 30.
you can try below answer given by #TimBiegeleisen that is also easy way.
just change your where clause as
WHERE `Notes` LIKE '%8!%%' ESCAPE '!

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 select rows containing ONLY cyrillic characters in UPPERCASE from the table using LIKE statement in MS SQL

I want to select rows where column [Name] contains ONLY Cyrillic characters in UPPERCASE, and comma and hyphen from the table using LIKE :
SELECT *
FROM Clients
WHERE NAME LIKE '%[А-Я][,-]%' COLLATE Cyrillic_General_CS_AS
Or using explicit pattern:
SELECT *
FROM Clients
WHERE NAME LIKE '%[АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ][,-]%' COLLATE Cyrillic_General_CS_AS
But these selects rows in which at least one character exists in pattern (but allows any other characters not exists in pattern).
Maybe using ^ (NOT predicate) excluding any other characters like this:
SELECT *
FROM Clients
WHERE NAME LIKE '%[^A-Z][./=+]%' COLLATE Cyrillic_General_CS_AS
But this requires enumeration a large number of unnecessary characters.
How best to make a selection?
Use a double negative. Search for rows where the column doesn't contain at least one character not in the set you're interested in:
SELECT *
FROM Clients
WHERE NAME NOT LIKE '%[^-АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ,]%' COLLATE Cyrillic_General_CS_AS
(I'm not quite sure what you were attempting to do by placing the hyphen and comma in a separate grouping, but I've moved them into the same group for now, since that seems to make some sense)

How to select rows with Chinese-Japanese characters?

How can I filter a column by Chinese-Japanese like characters? I am trying to do something like
SELECT * FROM my_table WHERE column LIKE '%[A-Za-z]%'
Is it possible for Chinese or Japanese characters?
When working with unicode string you will always need to prefix your string with N to tell sql server explicitly that there can be unicode characters in the operation. INSERT, UPDATE, SELECT and DELETE its true for all operations.
In your case when selecting data, in where clause you will need to prefix the Search string with N. Something like this....
SELECT *
FROM my_table
WHERE column LIKE N'%[A-Z]%' --<-- using Japanese characters here
OR Column LIKE N'%[a-z]%' --<-- using Japanese characters here
Below may work as it did for me.
SELECT * FROM my_table WHERE LEN(RTRIM(my_column)) <> DATALENGTH(RTRIM(my_column))
The len function may ignore trailing whitespaces so it's best to trim it before measuring the length.
Above came from advise on a Japanese web page.

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