Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
More from the grouping
Message
 
 
To
15/09/2010 17:01:36
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01481344
Message ID:
01481370
Views:
27
>>
>>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform