Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
GROUP BY on expression
Message
 
 
To
10/04/2003 02:59:23
General information
Forum:
Visual FoxPro
Category:
Client/server
Miscellaneous
Thread ID:
00775899
Message ID:
00775951
Views:
9
>>This should be quite simple but I can't find how to make that work. I am trying to group by on an expression field such as:
>>
>>
>>? SQLExec(lnHandle,"SELECT YEAR(AddDate) AS Test FROM News GROUP BY Test")
>>
>>
>>But, the only GROUP BY clause I can use is on a existing field. How can I GROUP BY on an expression?
>
>Ok, we have to reference with the entire syntax such as:
>
>
>? SQLExec(lnHandle,"SELECT YEAR(AddDate) AS Test FROM News GROUP BY YEAR(AddDate)")
>
>
>Thanks anyway

Michel,

There's a workaround that could be handy when expression is big or complicated and you don't want to repeat it in GROUP BY. It involves using derived table. For example,
lcSql = "SELECT test FROM (SELECT YEAR(AddDate) AS Test FROM News) GROUP BY test"
? SQLExec(lnHandle,lcSql)
Recent article in SQL Server magazine showed that this select generates the same execution plan as yours.
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform