Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SPT Statement
Message
 
 
To
16/10/2009 17:25:35
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01429697
Message ID:
01429700
Views:
47
>I am using SPT to get data for a chart. I need help with SQL statement so I get teh correct records.
>
>The table is a list of records that define users to particular project platforms with a schedule start date and finish date. One user can have several records but only one record per user can have null in the finish field. I basically want the latest schedule of the user or to know if the user has no current schedule.
>
>Here is the table layout. Null in the finish date indicates user is assigned indefinetly
>
>Userid Platform StartDate FinishDate
>SDE TC 06/05/2008 09/05/2009
>SDE TC 09/06/2009 null
>MJS PC 09/07/2009 09/10/2009
>KGT TC 09/10/2008 null
>JJJ SA 06/28/2009 05/01/2011

One of the solutions - SQL Server 2005 and up

;with cte as (select UserID, Platform, StartDate, FinishDate, row_number() over (partition by UserID order by FinishDate DESC) as RowNum) from myTable)

select * from cte where FinishDate IS NULL or RowNum = 1

See also http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/MSSQLServer/including-an-aggregated-column-s-related for the comprehensive analysis of available methods.
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