Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Very complicated SQL
Message
De
15/02/2014 15:20:11
 
 
À
15/02/2014 15:10:49
Walter Meester
HoogkarspelPays-Bas
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Web
Divers
Thread ID:
01594412
Message ID:
01594429
Vues:
41
>Not sure whether you mean "Any previous invoice detail record" or "The previous invoice detail record". Your example in another post just selects the TOP 1 of any record where NoStatus < > 7
>
>But I'd give it a shot:
>To get the invoiceDetails were for the last record NoStatus = 7 and has any previous record with NoStatus = 3
>
>
>SELECT InvoiceDetail.NoInvoice,InvoiceDetail.Numero
>    FROM InvoiceDetail I 
>    WHERE NoStatus = 7 AND NOT EXISTS(SELECT 1 FROM InvoiceDetail WHERE I.NoInvoice = NoInvoice AND Numero > I.Numero) 
>    AND EXISTS(SELECT 1 FROM InvoiceDetail WHERE I.NoInvoice = NoInvoice AND NoStatus = 3)
>
>
>If it needs to be the previous record and numero is one less than numer of the last record
>
>
>SELECT InvoiceDetail.NoInvoice,InvoiceDetail.Numero
>    FROM InvoiceDetail I 
>    WHERE NoStatus = 7 AND NOT EXISTS(SELECT 1 FROM InvoiceDetail WHERE I.NoInvoice = NoInvoice AND Numero > I.Numero) 
>    AND EXISTS(SELECT 1 FROM InvoiceDetail WHERE I.NoInvoice = NoInvoice AND NoStatus = 3 AND Numero = I.Numero-1)
>
>
>Is this what you are looking for ?

This is very good. 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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform