I am taking some data from Access table to Excel worksheet and they depends some parameters. My data list on access table includes for example:
1-x branch
2-y branch
3-z branch
4-t commercial branch
5-r commercial branch
6-w corporate branch
7-g corporate branch
On Excel VBA if I want to retrieve all of my data, I am creating a SQL query like:
sql = "select * from [table] where [Branches] like "%"
if I want to retrieve only commercial branches data:
sql = "select * from [table] where [Branches] like '%" & "commercial" & "%'"
and if I want to retrieve only corporate branch data:
sql = "select * from [table] where [Branches] like '%" & "corporate" & "%'"
and here is the question. What am I have to do if I want to retrieve data except corporate and commercial branches? What sort of sql query can we create?
Thanks a lot.
It's my bad, I could explain more clear. Before creating the query I am using my parameters like this:
Select Case main.Range("D6").Value
Case "ALL"
brnch = "%"
Case "CORPORATE"
brnch = "%" & "CORPORATE" & "%"
Case "COMMERCIAL"
brnch = "%" & "COMMERCIAL" & "%"
End Select
and my query is actually like that:
sql = "select * from [table] where [Branches] like '" & brnch & "'"
now what can I do to retrieve branches without commercials and corporates.
1 = Branch, 2 = CommercialBranch, 3 = CorporateBranch. Then filtering your query becomes trivial:WHERE [Table].[BranchCategoryId] IN(1, 2)ANDWHERE [Table].[BranchCategoryId] NOT IN(2, 3)main.Range("D6").Value, will have entries for NO commmercials and corporates?