Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Variable fields to group by in a view?
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01147438
Message ID:
01147937
Views:
20
>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.
Previous
Reply
Map
View

Click here to load this message in the networking platform