Note that there are some explanatory texts on larger screens.

plurals
  1. POFinding a single record in a table step-by-step by different requests
    primarykey
    data
    text
    <p>There is a table in a databse, let's call this table Document. This table has fields:</p> <ul> <li>MajorVersionNumber</li> <li>MinorVersionNumber</li> <li>ReleaseDate</li> </ul> <p>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.</p> <pre><code> var nextMinorVersion = Versions.FirstOrDefault((version) =&gt; (version.majorVersionNumber == currentVersion.majorVersionNumber) &amp;&amp; (version.minorVersionNumber == currentVersion.minorVersionNumber + 1)); if (nextMinorVersion != null) return nextMinorVersion.ReleaseDate; var nextMajorVersion = Versions.FirstOrDefault((version) =&gt; (version.majorVersionNumber == currentVersion.majorVersionNumber + 1) &amp;&amp; (version.minorVersionNumber == 0)); if (nextMajorVersion != null) return nextMajorVersion.ReleaseDate; return null; </code></pre> <p>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.</p> <p>I'm looking for a way to do it in SQL with relatively the same complexity as in C#.</p> <p>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.</p> <p><strong>UPDATE</strong> For those who are not deft with C# 3 I'll try to explain the rule in pseudocode:</p> <pre><code>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 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload