title: Can you do a select top in a case inside a subquery with a top one?
body: <p>I would like to perform a select statement inside a subquery that looks for the TOP 1, but only if the original result is Null. This is what I Have so far:</p>
  
  <pre><code>,(select TOP 1 Dimension from CUSTINVOICETRANS WHERE invoiceID= #TempCMs.INVOICEID AND [Inv Amt] = LINEAMOUNT
      (CASE
          WHEN DIMENSION IS NULL THEN
              select TOP 1 Dimension from LEDGERTRANS WHERE ledgertrans.voucher = #TempCms.INVOICEID and ABS([Inv Amt])= AMOUNTMST
      END)
  ) AS 'Department'
  </code></pre>
  
  <p>but i keep getting the following error message </p>
  
  <blockquote>
    <p>Msg 156, Level 15, State 1, Line 69
    Incorrect syntax near the keyword 'CASE'.
    Msg 102, Level 15, State 1, Line 73
    Incorrect syntax near ')'.</p>
  </blockquote>
  
  <p>I have no idea how to get past it</p>