Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Select and Update from CTE
Message
From
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:
01621611
Views:
35
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?
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
Next
Reply
Map
View

Click here to load this message in the networking platform