I'm working with a lot of year ranges and in the end they need to be "StartYear - EndYear".
So the following would data..
Sandra 1972
Sandra 1973
Sandra 1974
Sandra 1975
Sandra 1976
Johnny 2000
Johnny 2001
Johnny 2002
Johnny 2003
would in the end be:
Sandra 1972-1976
Johnny 2000-2003
I've got this kind of thing working no problem using SQL, grouping and min/max.. but when this happens:
Sandra 1972
Sandra 1973
Sandra 1975
Sandra 1976
Sandra 1977
Grouping them together and getting the max and the min year would be wrong as there is no 1974.
it should output:
Sandra 1972-1973
Sandra 1975-1977
Whats the smartest way of handling this? order the data by year subtract the lowest from the highest year and compare the result with the rowcount?
records returned: 5
Sandra 1972
Sandra 1973
Sandra 1975
Sandra 1976
Sandra 1977
Highest year : 1977
Lowest year : 1972
I'm tempted to program something in C# to handle this, but was wondering if there was a SQL way to deal with it?
wbochar
So the following would data..
Sandra 1972
Sandra 1973
Sandra 1974
Sandra 1975
Sandra 1976
Johnny 2000
Johnny 2001
Johnny 2002
Johnny 2003
would in the end be:
Sandra 1972-1976
Johnny 2000-2003
I've got this kind of thing working no problem using SQL, grouping and min/max.. but when this happens:
Sandra 1972
Sandra 1973
Sandra 1975
Sandra 1976
Sandra 1977
Grouping them together and getting the max and the min year would be wrong as there is no 1974.
it should output:
Sandra 1972-1973
Sandra 1975-1977
Whats the smartest way of handling this? order the data by year subtract the lowest from the highest year and compare the result with the rowcount?
records returned: 5
Sandra 1972
Sandra 1973
Sandra 1975
Sandra 1976
Sandra 1977
Highest year : 1977
Lowest year : 1972
I'm tempted to program something in C# to handle this, but was wondering if there was a SQL way to deal with it?
wbochar