Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
GROUP BY on expression
Message
 
 
À
10/04/2003 08:35:46
Information générale
Forum:
Visual FoxPro
Catégorie:
Client/serveur
Divers
Thread ID:
00775899
Message ID:
00775976
Vues:
9
>>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.
>
>Well, this approach is certainly interesting however there is probably an error in the syntax as it doesn't work. If I would execute the inside part of it, it would work. But, executing it as is won't work.


Yes, ther's an error. You've to give a name to a derived table
lcSql = "SELECT test FROM (SELECT YEAR(AddDate) AS Test FROM News) dt01 GROUP BY test"
>With that approach however, it would generate the entire set of records in a cursor before doing the external SQL. In my case, where I use it, it is to grab a group by expression of all year/month combinations, so doing it only in one simple SQL, with a long syntax for the field selection as well as the group selection would only select in one cursor the related records.

Your conclusion is incorrect because SQL Server doesn't work the way you described. The Query Optimizer analyzes whole query and decides how execute it. As I mentioned in the previous message ( I guess you missed it) Recent article in SQL Server magazine showed that this select generates the same execution plan as your query.
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform