Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Variable fields to group by in a view?
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Divers
Thread ID:
01147438
Message ID:
01147937
Vues:
21
>With a hardcoded field list like you're showing, it won't work. You must specify all non-aggregate fields in the GROUP BY clause. You would need to use expressions that look at the parameters for the field list instead of using them in the WHERE clause. Also, each expression in the WHERE clause is supposed to return a logical, not a string as you're doing. So, I would modify the statement like this:
>
>SELECT IIF(EMPTY(vp_state),'  ',State) as GrpState, ;
>       IIF(EMPTY(vp_orderdate),{},OrderDate as GrpOrdDate, ;
>       IIF(EMPTY(vp_itemcode),'  ',ItemCode as GrpItmCode, ;
>       count(*) ;
>   FROM mytable ;
>GROUP BY 1,2,3
>
>Note that I've renamed the fields State, OrderDate and ItemCode because sometimes VFP gets messed up if you use the same name as a field in the expression. You should probably also give a name to the count field so you can access it programmatically.
>
>The grouping will work in this case because the fields you're not interested in using for the grouping are all empty, which means they won't affect the order.

I'm using those kinds of IIFs with view parameters in the WHERE clause, but last time I tried using view parameters in the field list it made FoxPro unhappy. This looks like it's working with a quick test. Yes, I know WHEREs are logical, that was just pseudocode to describe what I was looking for.

Thanks.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform