Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Select and Update from CTE
Message
 
 
À
30/06/2015 14:41:34
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:
01621599
Message ID:
01621615
Vues:
27
>I think the update command is having too many duplicates from the child records. Presently, I have this:
>
>
>UPDATE Client SET Status=InvoiceTemp3.AddDate
> FROM Client
> INNER JOIN 
>(SELECT InvoiceTemp.NoClient,InvoiceTemp.AddDate FROM InvoiceTemp
> WHERE InvoiceTemp.RowNumber=2 AND InvoiceTemp.NoStatus=7 AND
>  EXISTS (SELECT InvoiceTemp.Numero FROM InvoiceTemp AS InvoiceTemp2
>   WHERE InvoiceTemp2.RowNumber=2 AND InvoiceTemp2.NoStatus=7 AND InvoiceTemp.NoClient=InvoiceTemp2.NoClient)) InvoiceTemp3
>   ON Client.Numero=InvoiceTemp3.NoClient
>
>
>Basically, if it would be just for the select, I would have:
>
>
>SELECT InvoiceTemp.NoClient,InvoiceTemp.AddDate FROM InvoiceTemp
> WHERE InvoiceTemp.RowNumber=2 AND InvoiceTemp.NoStatus=7 AND
>  EXISTS (SELECT InvoiceTemp.Numero FROM InvoiceTemp AS InvoiceTemp2
>   WHERE InvoiceTemp2.RowNumber=2 AND InvoiceTemp2.NoStatus=7 AND InvoiceTemp.NoClient=InvoiceTemp2.NoClient)
>
>
>So, if this gives 100 records, I need only the parent of those 100 detail records to be updated. So, I need to find the proper approach to include an UPDATE syntax from that SELECT command that will update the parent. Do you see how that can be adjusted?

So, for that parent, which child row (AddDate) do you want to grab?
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