Subject Re: [IBO] View, filter or ... ?
Author Helen Borrie
At 06:33 PM 03-03-01 +0200, you wrote:
>Sorry for the "Subject" of the original mail, I was in a hurry :)
>Hi !
>I wonder if somebody here on the list has a better idea for the
>following problem I have:
>1. I have a table with a "month,year,somedata" fields.
>2. When the user starts the program he is asked about the month and
>year he wants to work with and then the whole program only works with
>that "somedata".
>3. I've "solved" the problem by creating a view after he selects the
>month and data, something like
>create view curent_table as select * from table where (month=%d) and (year=%d)',
>After that in the whole program I'm only reffering to the "curent"
>view. I've done this because I find easier to use "select from
>curent_table ... " than appending to all
>queries something like 'where month=... and year=..." (select from
>table where (condition) AND month=... and year=...".

You need to use parameters. A view here is unnecessary.

select <fieldlist> from aTable
where month = :inmonth and year = :inyear

Then, when the user selects the month and year,

MyQuery.ParamByName('inMonth').AsInteger := <the selected month>;
MyQuery.ParamByName('inYear').AsInteger := <the selected year>;

An alternative would be to make the SQL

select <fieldlist> from aTable

and then use SQLWhereItems in the OnPrepareSQL event. It seems not to be necessary for your requirements, though, since you always use the same two input columns for your parameters.

>Note: the problem with this is that only one user could use the
>database at one time...or more users using only the selected month and
>year. In fact this is way I'm trying to find an alternative :)

Why ?

>4. There is another way of solving this by using filters, but
>it's almost the same as the last statement.

Filters are necessary only if the user needs to select different sets continuously. It doesn't seem as if this is what you want here.


All for Open and Open for All
InterBase Developer Initiative ยท