Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sql comparison
Message
 
 
To
10/02/2017 07:48:21
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Miscellaneous
Thread ID:
01647831
Message ID:
01647837
Views:
38
>HI
>
>I am trying to join two tables in a query based on the domain name in the email
>
>so I have
>
>
>select * from account a
>JOIN contact c
>ON
>right(c.[EMailAddress1], charindex('@', reverse(c.[EMailAddress1]))-1)  = right(a.[EMailAddress1], charindex('@', reverse(a.[EMailAddress1]))-1)
>
>
>which gives me the domain name in both emails.
>
>but when I run the query I get a failure when an email address has no @ sign ( few are empty)
>
>any idea whats the best way to deal with that in the query join.
>
>Thanks
>
>Nick Mason

The common solution is to use NULLIF function, e.g.

right(c.EmailAddress1, NULLIF(charindex('@', reverse(c.EMailAddress1)), 0) - 1) = ...
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform