Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Sql comparison
Message
 
 
À
10/02/2017 07:48:21
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Divers
Thread ID:
01647831
Message ID:
01647837
Vues:
39
>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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform