FHCHS/ldap-magic — pull request #4 by mexitek (2011-12-01 19:23:47+00:00)
Title: Query For Adding Gmail Users Is Failing

## Problem

There has been numerous reports of new students not having gmail accounts. The issue so far has been tracked down to the QueryNotExists() failing and throwing an exception.

### Query Fail

The problem is that the `LDAP_sqlusers table` and the `gmail_users` table
have different fields and the `EXCEPT` operator is failing. Solution
involves executing the `EXCEPT` operator only on the `pkey` if both
tables. This result set is then used as a subquery to determine who
needs to be updated.

### Failing Query

```sql
SELECT * FROM FHC_LDAP_sqlusersTable uptoDate
EXCEPT
SELECT * FROM FHC_LDAP_gmailusersTable AS outofDate
```

### Solution Query

```sql
SELECT
*
FROM
FHC_LDAP_sqlusersTable
WHERE
sAMAccountName in (
SELECT sAMAccountName
FROM FHC_LDAP_sqlusersTable
EXCEPT
SELECT sAMAccountName FROM FHC_LDAP_gmailusersTable
)
```

### Involved
@antgiant @alejandrard