Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Removing the last child record from same parent if seque
Message
 
 
À
29/06/2015 11:23:19
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2012
Application:
Web
Divers
Thread ID:
01621484
Message ID:
01621553
Vues:
36
>>Try (from the top of my head - play with the idea):
>>
>>;with cteRanges as (select *, row_number() over (partition by ClientID order by DateCol desc) as RowNumber,
>>
>> row_number() over (partition by ClientID order by DateCol desc)  - row_number() over(partition by ClientID order by DateCol desc,
>>case when status = 7 then 1 else 2 end) as Grp from Invoices)
>>
>>select * from cteRanges where Grp = 0 and RowNumber >=2
>
>Grp 1 and 2 is not used in the final query. What would be the use to calcultate it in the first command?

I don't understand your question. BTW, the query should be
select * from cteRanges where Grp = 0 and RowNumber >=2 and Status = 7
The idea is to mark consecutive ranges of the particular status.
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