samedi 25 juin 2016
How to dynamically modify subquery SQL in Access?
Suppose I have two Access queries getData_join and getData_static:
getData_static:
select * from someTable where someTable.property="value"
getData_join:
select * from someTable inner join otherTable on someTable.property=otherTable.property
The database has a lot of queries that call getData_join, e.g., items_getData:
select * from items inner join getData_join on items.property=getData_join.property
I want to set up a switch in the front end that will let the user select whether these queries call getData_static or getData_join. Rather than make two separate sets of queries, I was thinking about maybe having a generic getData query with a dummy clause like:
select * from someTable [insertClause]
and then defining the SQL on the fly using a QueryDef, like so:
Function modify_getData(isJoin As Boolean) As QueryDef
Dim qdf As QueryDef
Set qdf = CurrentDb.QueryDefs("getData")
If isJoin Then
qdf.sql = Replace(qdf.sql, "[insertClause]", "inner join otherTable on someTable.property=otherTable.property")
Else
qdf.sql = Replace(qdf.sql, "[insertClause]", "where someTable.property=""value""")
End If
Set modify_getData = qdf
End Function
The problem is that the front end doesn't call getData directly, it calls items_getData, so creating a modified getData QueryDef wouldn't be of use here. Is there a way to dynamically modify the SQL of a subquery in Access so that the modified SQL will get used by another query that calls it?
Inscription à :
Publier les commentaires (Atom)
Aucun commentaire:
Enregistrer un commentaire