Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
CTE not supported in Direct Query
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Divers
Thread ID:
01682562
Message ID:
01682565
Vues:
33
>Hi,
>
>equal query is:
>
>SELECT CTETable.NoField,CTETable.NoField2,
>            (SELECT COUNT(*) FROM Client WHERE CTETable.NoField=Client.NoField AND CTETable.NoField2=Client.NoField2) AS Field3
> FROM (SELECT MAX(Client.NoField) AS NoField, MAX(Client.NoField2) AS NoField2,
>                FROM Client
>                GROUP BY Client.NoGroup
>           )  CTETable
>
Thanks, in order to extract Client fields in the final result, I need to include a MAX() into the ID at the CTE level and establish the INNER JOIN after :
SELECT Client.MyField,CTETable.NoField,CTETable.NoField2,
            (SELECT COUNT(*) FROM Client WHERE CTETable.NoField=Client.NoField AND CTETable.NoField2=Client.NoField2) AS Field3
 FROM (SELECT MAX(Client.ID) AS ID, MAX(Client.NoField) AS NoField, MAX(Client.NoField2) AS NoField2,
                FROM Client
                GROUP BY Client.NoGroup
           )  CTETable
 INNER JOIN Client ON CTETable.ID=Client.ID
However, the field I add, such as Client.MyField, generates :

Column 'Client.MyField' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. This is confusing.

>But you can create view in db (with cte or not) and view use in Power BI.

That is correct. However, I wanted to get a query directly towards the tables.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform