![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have a table which lists player names, teams played for and the years they played there and my code looks like this SELECT AlsoPlayedFor.playerID, AlsoPlayedFor.teamID, AlsoPlayedFor.TeamName, Min([AlsoPlayedFor].[Year]) & "-" & Max([AlsoPlayedFor].[Year]) AS [Year] FROM AlsoPlayedFor GROUP BY AlsoPlayedFor.playerID, AlsoPlayedFor.teamID, AlsoPlayedFor.TeamName; which takes the Min year and the Max Year and displays it like "Year- Year" But lets say for example the player played for 5 years so it 1990, 1991, 1992, 1993, 1995 It would display as 1990-1995 but I want it to display as 1990-1993, 1995, is this possiable??? Also I need it to gothe other wayso if the years are 1990, 1992, 1993, 1994, 1995 I want that to display as 1990, 1992-1995. |
#3
| |||
| |||
|
#4
| |||
| |||
|
| I could suggest a query which in SQL 2005 at least give you a comma- separated list of the years. Collapsing adjacent years into ranges appears to make things a lot more complicated. |
#5
| |||
| |||
|
|
Erland Sommarskog wrote: I could suggest a query which in SQL 2005 at least give you a comma- separated list of the years. Collapsing adjacent years into ranges appears to make things a lot more complicated. Here is a recursive solution that will do the job when MAXRECURSION is no greater than the number of separate years for one individual player. Some of the complication is to get around limitations in what a recursive query can contain (no GROUP BY, for example). The idea is slippery, but not quite as messy as it looks. snip |
|
select Pid,lastwrite, yrs + case when lastwrite < lastfound then rtrim(lastfound) else ','+rtrim(lastfound) end from AllSteps where rk = 1 go -- Steve Kass -- Drew University -- http://www.stevekass.com -- 95508D54-0B01-431B-8B58-880146787216 |
#6
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |