SELECT
  IL.CMSInvNo,
  IL.CMSLineNo,
  IL.Description,
  CASE IL.TaxTypeID
    WHEN  6 THEN 'ZERORATED'
    WHEN  7 THEN 'EXEMPTOUTPUT'
    WHEN 17 THEN 'BADDEBT'
    ELSE 'OUTPUT3'
  END AS TaxRateCode,
  IL.LineQuantity,
  IL.UnitPriceExcl,
  IL.UnitPriceIncl
FROM
  taInvoiceLine AS IL
WHERE
  (IL.CMSInvNo IN (@pCMSInvNo)) AND
  (IL.LineQuantity > 0)
ORDER BY
  IL.CMSInvNo,
  IL.CMSLineNo
