I have a trigger, that checks if the domain of the email, exists in another table (domain).
Table user:
+------------------+ +------------------+
| email | | domain |
+------------------+ +------------------+
| Joe@gmail.com | | gmail.com |
| Jack@live.com | | live.com |
| Berti@outlook.com| |------------------|
|------------------|
The trigger is:
IF EXISTS (
SELECT 1
FROM [USER] AS U INNER JOIN inserted AS I
ON U.EMAIL = I.EMAIL
WHERE REPLACE(RIGHT(U.EMAIL, CHARINDEX('@', U.EMAIL)-2),'_',' ') NOT IN (
SELECT DOMAIN_NAME
FROM ALLOWED_DOMAIN
)
)
The trigger doens't work correctly so i runned the following query:
select REPLACE(RIGHT(U.EMAIL, CHARINDEX('@', U.EMAIL)-2),'_',' '), EMAIL
from [USER] U
Which gives the following result:
| unknown | email |
+----------------|--------------- |
| gmail.com | Joe@gmail.com |
| ive.com | Jack@live.com |
| ti@outlook.com | Berti@outlook.com|
+----------------|------------------|
For now it looks like the trigger applies the amount of characters from the 1st record to all records in the table... How can i fix the trigger so it works multiple row?