Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Select and Update from CTE
Message
 
 
To
30/06/2015 14:41:34
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2012
Application:
Web
Miscellaneous
Thread ID:
01621599
Message ID:
01621615
Views:
29
>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform