Use Derived/Temporary column in Where Clause : <p>Here Is my query. The Issue is that I am trying to apply the derived 'LineNo' field as the where clause. The query below does not work. Simply put, if the Value of a LineHrs column is > 0 it will set this derived column to a given value (eg If Line5Hrs = 1.4 then 'LineNo' for the row = 'Line 5'). I want to use this value to search for all jobs on a specific line.</p>

<pre><code>SELECT      tblA.PROJECT_ID, 
            tblB.Line1Hrs, 
            tblB.Line2Hrs, 
            tblB.Line3Hrs, 
            tblB.Line4Hrs,
            tblB.Line5Hrs,
            tblB.Line6Hrs, 
            tblB.Line7Hrs, 
            "LineNo" =
                        CASE 
                            WHen tblB.Line1Hrs &gt; 0 Then 'Line1'
                            WHen tblB.Line2Hrs &gt; 0 Then 'Line2'
                            WHen tblB.Line3Hrs &gt; 0 Then 'Line3'
                            WHen tblB.Line4Hrs &gt; 0 Then 'Line4'
                            WHen tblB.Line5Hrs &gt; 0 Then 'Line5'
                            WHen tblB.Line6Hrs &gt; 0 Then 'Line6'
                            WHen tblB.Line7Hrs &gt; 0 Then 'Line7'
                        End
FROM            tblA INNER JOIN tblB
                ON tblA.blah = tblB.blah AND
                tblA.blab = tblB.blab

WHERE         LineNo = 'Line5'
</code></pre>
