I am trying to add a query in my current SQL INSERT INTO statement. Below is my table and current sql statement.
I have 3 tables:
Table1: UserID, Username.
Table2: UserID, Status.
Table3: UserID, Username, Issue
Currently I only have 3 SELECT statement which fulfills the above 3 checks and INSERT the result into Table3:
1.
Insert in to Table3(userid,issue)
SELECT t1.userid,'check no.1'
FROM table1 t1
FULL OUTER JOIN table2 t2 ON t1.userid = t2.userid
where t1.userid not null and t2.userid is null
2.
Insert in to Table3(userid,issue)
SELECT t1.userid,'check no.2'
FROM table1 t1
inner JOIN table2 t2 ON t1.userid = t2.userid
where t2.status = 'DELETE'
3.
Insert in to Table3(userid,issue)
SELECT t2.userid,'check no.3'
FROM table2 t2
right outer JOIN table2 t2 ON t1.userid = t2.userid
where t2.status <> 'DELETE' and t1.userid is null
Now I wish to add in another additional check which is to check for duplicated userid in BOTH T1 AND T2:
- Check for same userid with same caps (e.g. E01 and E01 should not exist)
- Check for same userid but different caps (e.g. E01 and e01 should not exist)
How can I code the 4th sql query which specially checks for duplicated userids?
Thank you for the help.
Edited:
You can use the COLLATE as shown in the OLD section to do a case sensitive check, if you need.
I used RANK=2 to insert only one entry for duplicate userID
OLD:
You can use the COLLATE to do a case sensitive check