title: How to merge two columns from CASE STATEMENT of DIFFERENT CONDITION
body: <p>My expected result should be like</p>
  
  <pre><code>----invoiceNo----
  T17080003,INV14080011
  </code></pre>
  
  <p>But right now, I've come up with following query.</p>
  
  <pre><code>SELECT AccountDoc.jobCode,AccountDoc.shipmentSyskey,AccountDoc.docType,    
      CASE AccountDoc.docType
      WHEN 'M' THEN
      JobInvoice.invoiceNo
      WHEN 'I' THEN
      (STUFF((SELECT ', ' + RTRIM(CAST(AccountDoc.docNo AS VARCHAR(20)))
       FROM AccountDoc LEFT OUTER JOIN JobInvoice
       ON AccountDoc.principalCode = JobInvoice.principalCode AND 
       AccountDoc.jobCode = JobInvoice.jobCode
       WHERE (AccountDoc.isCancelledByCN = 0)
            AND (AccountDoc.docType = 'I')
            AND (AccountDoc.jobCode = @jobCode)
            AND (AccountDoc.shipmentSyskey = @shipmentSyskey)
            AND (AccountDoc.principalCode = @principalCode) FOR XML 
            PATH(''), TYPE).value('.','NVARCHAR(MAX)'),1,2,' '))
      END AS invoiceNo
  
  FROM AccountDoc LEFT OUTER JOIN JobInvoice
  ON JobInvoice.principalCode = AccountDoc.principalCode AND 
  JobInvoice.jobCode = AccountDoc.jobCode
  WHERE (AccountDoc.jobCode = @jobCode)
          AND (AccountDoc.isCancelledByCN = 0)
          AND (AccountDoc.shipmentSyskey = @shipmentSyskey)
          AND (AccountDoc.principalCode = @principalCode)
  </code></pre>
  
  <p>OUTPUT:</p>
  
  <pre><code>----invoiceNo----
  T17080003
  INV14080011
  </code></pre>
  
  <p>Explanation:</p>
  
  <p>I want to select docNo from table AccountDoc if <code>AccountDoc.docType = I</code>.
  Or select invoiceNo from table JobInvoice if <code>AccountDoc.docType = M</code>. </p>
  
  <p>The problem is what if under same jobCode there have 2 docType which are M and I, how I gonna display these 2 invoices?</p>