Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Group by result in a string...
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Desktop
Divers
Thread ID:
01462361
Message ID:
01462363
Vues:
40
>I need to report in one string a list of value from a group by.
>Ex:
> SELECT Sort_Plan_Number
> FROM dbo.StagingRollup
> WHERE Valid_Status = -3300
> GROUP BY Sort_Plan_Number
>
>I can use this select in a cursor and then fetch it but I think with SQL 2008 there is a better way.
>Anyone know this one?
;with cte as (select *, row_number() over (
partition by Sort_Plan_Number order by Sort_Plan_Number) as Row
 from dbo.StagingRollup 
 WHERE Valid_Status = -3300 )

select * from cte where Row = 1
Take a look here

Including an Aggregated Column's Related Values
Including an Aggregated Column's Related Values - Part 2
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform