Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
More from the grouping
Message
 
 
À
15/09/2010 16:11:00
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:
01481344
Message ID:
01481346
Vues:
24
>This afternoon, and thanks to those who helped me with those SQL, I was able to define the required SQL I was looking for. This works. Basically, the actual command is:
>
>
>SELECT RO.FirstName
>FROM (SELECT TOP 10 Event.RO_No,Min(Event.DateTime) AS LastUpdate
> FROM Event
> INNER JOIN RO ON Temp.RO_No=RO.RO_No
> GROUP BY Event.RO_No
> ORDER BY MIN(Event.Datetime)) Temp
>INNER JOIN RO ON Temp.RO_No=RO.RO_No
>
>
>So, this returns something like this:
>
>
>Ro_No       DateTime
>  1         2007-12-17 14:41:25.704
>  3         2007-12-17 14:42:25.704
>  7         2007-12-17 14:43:25.704
> 22         2007-12-18 15:41:25.704
> 23         2007-12-19 16:41:25.704
> 24         2008-12-20 07:41:25.704
> 25         2009-12-17 08:41:25.704
> 46         2009-12-17 05:41:25.704
> 48         2009-12-18 05:41:25.704
> 49         2009-12-19 14:41:25.704
>
>
>But, Ro_No, in the Event table appears in multiple records. The reason is that the Event table logs everything when there is a change in the record. So, I have a robot process which processes 10 records at a time. So, in the next loop, it will execute the same SQL again and obtain a new batch of 10 records. However, in that new batch, I may end up with a RO_No that I already processed. In our design, there is only a need to process the last one from the Event table. I do not know if that is possible here, if that would require a derived SQL or else.
>
>The problem I have presently is that I have about 2000 records to process. So, this would make it 200 times. But, I only have 56 records in the RO table. So, at most, if I can refine this SQL, I would only have to do 6 loops.

Why not to add a bit field IsProcessed (or Processed) to RO table? When you do the work in your robot process you update the flag and therefore you will not select same records again.
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