Need help dynamically retrieving queries

  • Thread starter Thread starter mike_hass
  • Start date Start date
M

mike_hass

I have inherited a set of complex Access Databases, one for each state
in the US. They are all based on a similar principle and processes,
and have the same goal of calculating a price to charge each customer.
However, each state has slightly different logic to calculate the cost
per customer. I can boil that differences down to the SQL queries and
standardize almost everything else. There are 30 queries (one for each
step in the rating logic) that are different by state. I would like to
have one Setup Model, that can be used to create the state specific
models. Therefore, if I add functionality to 1 model, I don't have to
manually add it to all the other models.

To address the SQL differences, I thought of storing the actual SQL for
the query in a "Setup Table". In the "Setup Table", each state would
be a separate column and each row would represent one of the 30 queries
in the rating logic. Therefore, the intersection of the column (i.e.
State) and row (i.e. Step), would be the right SQL to run. I would
like to pick up the SQL string as text and automatically create the
actual query object in Access. I would like to create the query object
because the end user needs to modify the query at times via Access's
query design view. I am not worried about saving the modified query
back to the "Setup Table". I can do that manually after they have
finalized their model. The SQL queries range from updated and append
queries to deletes and basic selects.

To a lesser extend, I have the same issue with reports and with
enabling/ disabling buttons based on the applicability of the button to
the state.

Any help would be greatly appreciated.

Thanks,
Mike
 
suggest you use a normalized design for your SetupTable, as

tblStateSQLs
SQLID (primary key)
StateName (or StateID, if you have a separate table that lists all states)
SQLString
RunOrder (use this field if you need to create, or run, the SQL statements
in a specific order - just number a state's records as 1, 2, 3.....28, 29,
30)

in the above design, you'll have one record for each SQL statement for each
state (30 records for each state - that being one for each SQL). it will be
easy to write code to loop through each SQL statement record for any given
state, or for all the states. again, if you need to loop through the records
in a specific order, use the RunOrder field.

hth
 
Thanks for your thoughts on this. I had not considered using a run id.
That is a great way to specify the order of operations. In this
program, the order is critical and could be different by state. thanks
again!
Mike
 
Back
Top