tony
tony

Reputation: 67

VBA - SQL request with filter

I would like to do a SQL request in VBA that avoids some values.

  1. First I do a request that give me the values I do not want:

    I put those values in a table a for example: a = (1, 25, 3)

  2. Then I would like to do a request like:

    rst.Source = "SELECT TableNumerosClients.NOM_CLIENT ," & _
                 "FROM table.Clients WHERE NOT table.id in a ;"

My problem here is a, I do not know how to make the query understand that a = (1, 25, 3)

Thanks

Upvotes: 1

Views: 65

Answers (1)

Lee Mac
Lee Mac

Reputation: 16015

Assuming that your example object a is genuinely a table and not an array of values, there are a couple of ways to accomplish this:

Using a subquery in the WHERE clause:

select c.nom_client
from clients c
where c.id not in (select a.id from a)

Using a LEFT JOIN:

select c.nom_client
from clients c left join a on c.id = a.id
where a.id is null

Upvotes: 2

Related Questions