Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Removing the last child record from same parent if seque
Message
 
 
To
29/06/2015 09:02:57
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2012
Application:
Web
Miscellaneous
Thread ID:
01621484
Message ID:
01621550
Views:
48
>>You can use some arbitrary number, say, where RowNumber between 2 and 1000 and otherwise the condition will remain exactly the same as my original select statement.
>
>Yes, but you need to know the limit. That is why I opted for COUNT.

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
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform