Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
First and last based on same SQL
Message
De
10/10/2014 09:25:28
 
 
À
10/10/2014 01:12:19
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2012
Application:
Web
Divers
Thread ID:
01609079
Message ID:
01609126
Vues:
36
>Here's one solution with a CTE and then 2 correlated subqueries. If there's a risk of a tie (2 names for the same date), you could do a SELECT TOP 1 Name
>
>As I look at this, I'm pretty sure there's an easier way. I'll post again if I can think of one (or maybe someone else has an idea).
>I'm sure there are variations of this that could be done with CROSS APPLY and other approaches, but this at least should work.
>
>
>;WITH TempCTE AS (SELECT ClientNo, MAX(AddDate) as MaxDate, MIN(AddDate) as MinDate
>                                     FROM dbo.Test  GROUP BY ClientNo)
>
>
>SELECT TempCTE.ClientNo , 
>        (SELECT Name from dbo.Test  WHERE TempCTE.ClientNo = Test.ClientNo AND Tempcte.MinDate = Test.AddDate) as FirstName, 
>        (SELECT Name from dbo.Test  WHERE TempCTE.ClientNo = Test.ClientNo AND Tempcte.MaxDate = Test.AddDate) as LastName
>FROM TempCTE 
>
Thanks, that is another possible way.
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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform