Tuesday, March 6, 2012

"dynamical" view

Hi,

I'm currently migrating an MS Access database to SQL 2000 Standard, and i have a problem with queries migration.

In acccess, a screen allows me to view some informations depending on Criteria, and results are returned with a query (we'll call it Q1).

Then, when correct data are returned by the query Q1, some other queries compute sums, average, group by orders, based on Q1's results.

Now my question : as in sql server, a view cannot accept parameters, the solution i adopted is :

- create a generic Q1 view, not filtered.

- then, all the subqueries based on this view are Functions or Stored procedures, which accepts parameters and do the filter on the main view (Q1).

The problem is that writing such functions or stored procedures is quite long, and interface code has to be deeply modified to use these parameters.

First, I had the idea of creating a temporary table, in which i would have inserted the good data, an the other queries would have used it. Unfortunately, views can't use temporary tables.

Any good idea is expected. Thanks in advance,

So, i found a first way to do this, maybe not the best, but it seems to work correctly.

I generate the script to dynamically generate the view with the correct "where" statements.

The view's name is MyView_ + Host_Id().

It should work since we don't use a citrix server for client hosting...

No comments:

Post a Comment