There is a table in a databse, let's call this table Document. This table has fields:
- MajorVersionNumber
- MinorVersionNumber
- ReleaseDate
There are rules to determine the order of versions and their expiration dates. I'll give the rule of finding expiration date of a version in C# 3 because it looks more easy to read then in English.
var nextMinorVersion = Versions.FirstOrDefault((version) =>
(version.majorVersionNumber == currentVersion.majorVersionNumber) &&
(version.minorVersionNumber == currentVersion.minorVersionNumber + 1));
if (nextMinorVersion != null) return nextMinorVersion.ReleaseDate;
var nextMajorVersion = Versions.FirstOrDefault((version) =>
(version.majorVersionNumber == currentVersion.majorVersionNumber + 1) &&
(version.minorVersionNumber == 0));
if (nextMajorVersion != null) return nextMajorVersion.ReleaseDate;
return null;
Now this rule must be implemented in SQL for MS SQL Server 2005 and 2008. I tried and could make up only very cumbersome, inefficient and ureadable expressions. Taking into account how trivial it looks in C#, I think I can't do it as easy just because I'm not deft with SQL.
I'm looking for a way to do it in SQL with relatively the same complexity as in C#.
Sorry for such a narrow question, I don't know how to generalize this. Suggestions on generalizing the question and it's title are also very appreciated.
UPDATE For those who are not deft with C# 3 I'll try to explain the rule in pseudocode:
if exists nextMinorVersion so that
nextMinorVersion.majorVersionNumber = currentVersion.majorVersionNumber and
nextMinorVersion.minorVersionNumber = currentVersion.minorVersionNumber + 1
then expirationDate = nextMinorVersion.ReleaseDate
else if exists nextMajorVersion so that
nextMajorVersion.majorVersionNumber = currentVersion.majorVersionNumber + 1 and
nextMinorVersion.majorVersionNumber = 0
then expirationDate = nextMajorVersion.ReleaseDate
else expirationDate = null