Finding a Specific Character and/or String SQL Server 2008

SuGo

I have two columns which contain email info. Column A, Column B. Now, in these fields, emails SHOULD be as such:

 Column A                 Column B
 [email protected]; [email protected]         [email protected]; [email protected]
 [email protected];[email protected]          [email protected];[email protected]

However, in an effort to do some data quality checks and such, it turns out that MANY entries are instead not following this format. I am trying to find all the outliers, and I have identified the outliers to take the form as such:

[email protected] and [email protected]
[email protected], [email protected] (uses comma so it is incorrect)
[email protected] or [email protected]
[email protected] / [email protected]

There could be other wrong characters or words that make the format incorrect. But I hope these examples pinpoint the issue.

What I am trying to do: Create a query that will pinpoint all instances that are NOT in the correct format, so that the problem points can be found and edited later, but that's a different topic :)

Here is a Query I have so far:

SELECT     A_EMAIL, B_EMAIL, NAME, ID
FROM         NAMES

WHERE A_EMAIL LIKE ('and %') OR A_EMAIL LIKE ('or %') 
OR B_EMAIL LIKE ('and %') OR B LIKE ('or %')

This is using LIKE and the % is with a space in between. However, this returns no results, and I know such results definitely do exist. But I would like to build a logic that would bring me back everything that isn't in the proper format instead of trying to use LIKE 'XYZ' because even though I know most of the problem issues, I could still miss some.

However, if such a thing isn't possible via SQL. Then I would still like to get my current logic of using LIKE ('XYZ %') to work instead which even though not an optimal route, should still be able to help me in my goal someway.

Vladimir Baranov

Your query is fine, you just missed one % in it. Instead of this

WHERE A_EMAIL LIKE ('and %') OR A_EMAIL LIKE ('or %') 
OR B_EMAIL LIKE ('and %') OR B LIKE ('or %')

you should use this

WHERE A_EMAIL LIKE ('%and %') OR A_EMAIL LIKE ('%or %') 
OR B_EMAIL LIKE ('%and %') OR B LIKE ('%or %')

Your original query looks for values that start with 'and ', while you are interested in cases where 'and ' appears anywhere inside the column value.

Of course, this is a one-off solution to your immediate problem. The permanent solution is not to store several e-mails in the same column in the first place.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

SQL Server 2008: Finding a value from a string

From Dev

SQL server 2008 finding databases owned by a specific user

From Dev

SQL server 2008 finding databases owned by a specific user

From Dev

Finding ranges of specific character in a string

From Dev

Finding a Specific Character in SQL Statement

From Dev

Append a specific character after each character of a string in sql server

From Dev

Finding the last specific character type in a string

From Dev

Finding string between 2 specific character

From Dev

How to split a string after specific character in SQL Server

From Dev

Replace Last character in SQL Server 2008

From Dev

SQL Server 2008 and Unicode Character comparison

From Dev

How to search Special character (%) in SQL Server 2008

From Dev

SQL Server 2008 and Unicode Character comparison

From Dev

SQL Server 2008 and Connection String

From Dev

Conversion failed when converting date and/or time from character string in SQL SERVER 2008

From Dev

Sql Server 2008: Conversion failed when converting date and/or time from character string

From Dev

How do I get a specific string UNTIL a specific character out of a string in SQL Server?

From Dev

SQL Server 2008 - Select query specific item

From Dev

Finding Median between TWO dates SQL Server 2008

From Dev

How to convert a string to integer in SQL Server 2008?

From Dev

Remove string between () including () in SQL Server 2008

From Dev

Converting a string to a datetime in SQL Server 2008

From Dev

Comparing String,if it is NULL in Sql Server 2008

From Dev

Comparing String DateTime in SQL Server 2008

From Dev

How to convert a string to integer in SQL Server 2008?

From Dev

Finding a string in XML column using sql server

From Dev

Finding "-" Character in a String in JAVA

From Dev

How to find the First Character starting in SQL Server 2008

From Dev

How to find the First Character starting in SQL Server 2008

Related Related

  1. 1

    SQL Server 2008: Finding a value from a string

  2. 2

    SQL server 2008 finding databases owned by a specific user

  3. 3

    SQL server 2008 finding databases owned by a specific user

  4. 4

    Finding ranges of specific character in a string

  5. 5

    Finding a Specific Character in SQL Statement

  6. 6

    Append a specific character after each character of a string in sql server

  7. 7

    Finding the last specific character type in a string

  8. 8

    Finding string between 2 specific character

  9. 9

    How to split a string after specific character in SQL Server

  10. 10

    Replace Last character in SQL Server 2008

  11. 11

    SQL Server 2008 and Unicode Character comparison

  12. 12

    How to search Special character (%) in SQL Server 2008

  13. 13

    SQL Server 2008 and Unicode Character comparison

  14. 14

    SQL Server 2008 and Connection String

  15. 15

    Conversion failed when converting date and/or time from character string in SQL SERVER 2008

  16. 16

    Sql Server 2008: Conversion failed when converting date and/or time from character string

  17. 17

    How do I get a specific string UNTIL a specific character out of a string in SQL Server?

  18. 18

    SQL Server 2008 - Select query specific item

  19. 19

    Finding Median between TWO dates SQL Server 2008

  20. 20

    How to convert a string to integer in SQL Server 2008?

  21. 21

    Remove string between () including () in SQL Server 2008

  22. 22

    Converting a string to a datetime in SQL Server 2008

  23. 23

    Comparing String,if it is NULL in Sql Server 2008

  24. 24

    Comparing String DateTime in SQL Server 2008

  25. 25

    How to convert a string to integer in SQL Server 2008?

  26. 26

    Finding a string in XML column using sql server

  27. 27

    Finding "-" Character in a String in JAVA

  28. 28

    How to find the First Character starting in SQL Server 2008

  29. 29

    How to find the First Character starting in SQL Server 2008

HotTag

Archive