Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
More from the grouping
Message
 
 
À
15/09/2010 17:01:36
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:
01481370
Vues:
26
>>
>>SELECT TOP 10 Event.RO_No,
>>Min(Event.DateTime) AS LastUpdate,
>>min(Ro.FirstName) as FirstName
>> FROM Event
>>inner join RO on Event.Ro_No = RO.Ro_No
>> WHERE Event.Event_DateTime>'SomDate' GROUP BY Event.RO_No
>> ORDER BY MIN(Event.Datetime) 
>>and not exists(select 1 from Event E where E.DateTim < ='SomeDate' and E.Ro_No = RO.Ro_NO)
>
>It is that I have dozens of lines in the main SQL, not just the FirstName. So, I need to find a way to keep the sub SQL as is and collect everything I need after in the main SQL.

It's the same thing - adjust the inner select (derived table) only.
select RO.*, E.* from RO inner JOIN
(select top (10) Event.RO_NO, min(DateTime) as LastUpdate 
from Event where DateTime > 'DateValue'
and not exists (select 1 from
Event E where DateTime <='DateValue' and E.Ro_No = Event.Ro_No)
GROUP BY Ro_NO
order by MIN(Event.DateTime)) E on RO.RO_NO = E.RO_NO
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