开发者

How filter a dataset based on a nested dataset record count?

I have a Dataset i want to apply a filter based on a dataset-type field record count, something like: 'NESTED_DATA开发者_如何学JAVASET_FIELD.RecordCount > 0'


If the dataset comes from a SQL based storage engine, use a select distict query on the joined table with only fields from the master table in the result set. Let the SQL engine do the work for you.


Depending on your situation, you can use:

  1. In OnFilterRecord event you can have:

    Accept := myDataSetField.NestedDataSet.RecordCount>0;

  2. If you have a SQL backend you can use the Exists or Count in order to fetch only the records which you need. Perhaps is the best approach if you are over a network. However I don't know what infrastructure you have.

  3. In OnFilterRecord event you can have:

    Accept := not myDataSetField.IsNull; //Just testing if the DataSet field is empty - which is one of the fastest ways to do it ...but this depends on the structure of your data / dataset etc.

  4. Sometimes is better to have a dedicated field in your DataSet / Table to specify this status because usually getting such info from the nested dataset can be expensive. (One must fetch it at least partially etc.)

  5. Also, for the same considerations (see 4. above) perhaps you can have a Stored Procedure (if your DB backend permits) to get this info.

HTH

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜