Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Very complicated SQL
Message
From
16/02/2014 11:27:55
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01594412
Message ID:
01594456
Views:
31
>
>;with cteInvoiceDetails as (select *, row_number() over (partition by InvoiceNo order by InvoiceDate DESC) as Rn)
>select * from cte c1 where Rn = 1 and NoStatus = 7 and 
>exists (select 1 from cte c2 where c2.InvoiceNo = c1.InvoiceNo and c2.Rn = 2 and NoStatus = 3) -- so, the previous row has status 3 and therefore this row may be deleted
>
Interesting approach, thanks
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
Previous
Reply
Map
View

Click here to load this message in the networking platform