Search for case sensitive entries

I have a requirement for getting case sensitive entries from only one column of a table.

ie them is the email_address column, from which I have to find the email address, which is the same, but they are in different cases.

eg:

email_ address
---------------
abc@gmail.com
hef@gmail.com
ABC@gmail.com
hrf@gmail.com

from the above example. I need a query to retrieve only records abc@gmail.comand abc@gmail.comfrom a column email_address.

+4
source share
10 answers

Personally, I don't like this approach, but it seems to be the only solution I have right now, and it also works with mixed cases:

select * from test t 
    where   
    email_address in 
    (
    select email_address from test group by email_address having count(email_address)> 1        
    )
    and left(email_address, charindex('@', email_address) -1 ) collate SQL_Latin1_General_CP1_CS_AS
        not in (select left(email_address, charindex('@', email_address) -1 ) from test 
                        where email_address collate SQL_Latin1_General_CP1_CS_AS <> t.email_address )

p / s: u need to replace "test" with your actual table name

+1

SELECT  *
FROM    table T 
JOIN    tALBE T2 
ON      T.EMAIL             =   T2.EMAIL
AND  CONVERT(varbinary,T.EMAIL)    <>       CONVERT(varbinary,T2.EMAIL)
+1

, , , -

WITH CTE AS(
SELECT
email_address 
FROM TEST
GROUP BY email_address
Having count(1) > 1
)
SELECT TEST.email_address 
FROM TEST
INNER JOIN CTE ON
TEST.email_address=CTE.email_address

SQL FIDDLE

+1

Where [email_ address] COLLATE Latin1_General_100_CI_AI = 'abc@gmail.com'
+1

,

Select * from TableName where email_ address COLLATE Latin1_General_CS_AS = 'Your I/p Values'
+1

:

SELECT *
FROM
( VALUES ('abc'), ('ABC'), ('AbC')
) x(name)
WHERE name COLLATE Latin1_General_100_CS_AI = 'abc'
+1

1. COLLATE Latin1_General_CS_AI 2. BINARY_CHECKSUM

create table EmailDetails(EID int identity(1,1),EmailAddress varchar(100))
insert into EmailDetails values('abc@gmail.com')
insert into EmailDetails values('ABC@gmail.com')
select EmailAddress from EmailDetails 
where EmailAddress COLLATE Latin1_General_CS_AI=LOWER(EmailAddress)
select EmailAddress from EmailDetails 
  where EmailAddress COLLATE Latin1_General_CS_AI='abc@gmail.com'
select EmailAddress from EmailDetails 
where BINARY_CHECKSUM(EmailAddress)=BINARY_CHECKSUM('abc@gmail.com')
+1

,

declare @t table(email varchar(100))

insert into @t values('abc@gmail.com'),('hef@gmail.com'),('ABC@gmail.com'),('hrf@gmail.com')

declare @searchEmail varchar(100 )= 'ABC@gmail.com'

---1st approach 
SELECT *
FROM @t
WHERE   
    email = @searchEmail COLLATE SQL_Latin1_General_CP1_CS_AS

---2nd approach to convert in binary
select * from @t where CAST(email  as varbinary(100))  =  CAST(@searchEmail as varbinary(100))  

Collation, .

, :

, , .

WHERE ( SQL Server)?

SQL Server -?

0

sql-. , , .. , "%" , WHERE:

SELECT * FROM TABLE WHERE COLUMN = %@VARIABLE% 

,

0

"LIKE" SQL:)

SELECT email_address FROM <tablename> WHERE email_address like 'abc@gmail.com'

, :)

, Begin with, Ends with, Contains With

SELECT email_address FROM <tablename> WHERE email_address like '%abc%' //contains with
SELECT email_address FROM <tablename> WHERE email_address like 'abc%' //Begin with
SELECT email_address FROM <tablename> WHERE email_address like '%abc' //Ends with
-2

Source: https://habr.com/ru/post/1545613/


All Articles