title: The ntext data type cannot be selected as DISTINCT because it is not comparable
body: <p>I have a query which is joined by multiple queries and multiple tables if i run this query I am getting an error like this :</p>
  
  <blockquote>
    <ol>
    <li>The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.</li>
    <li>The ntext data type cannot be selected as DISTINCT because it is not comparable.</li>
    </ol>
  </blockquote>
  
  <p>The table structure is:</p>
  
  <p><a href="https://i.stack.imgur.com/kr2a9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kr2a9.png" alt="Design of tables and datatype"></a></p>
  
  <p>and the query is this :</p>
  
  <pre><code>SELECT p.Proj_uid, p.proj_name,p.Agency,p.District,p.Division,p.ProjStatus,Civilbill80.billcount as Civilbill80, 
  Civilbill20.billcount as Civilbill20 ,Civilbillpay.billcount as FinalCivilBill,CivilWorkslip.billcount as CivilWorkslip,
   Electribill80.billcount as Electricbill80, Electribill20.billcount as Electricbill20, Electribillpay.billcount as FinalElectriBill,
   ElectriWorkslip.billcount as ElectriWorkslip  FROM tempproj p
    LEFT JOIN (
               SELECT distinct(Proj_name),BillType,COUNT(1) as billcount  FROM payment_80   where BillType='CIVIL'
                GROUP BY Proj_name, BillType ) Civilbill80 ON Civilbill80.Proj_name = p.proj_name 
   LEFT JOIN (
               SELECT distinct(Proj_name),billtype,COUNT(1) as billcount FROM Payment_20    where billtype='CIVIL'
                GROUP BY Proj_name, billtype ) Civilbill20 ON Civilbill20.Proj_name = p.proj_name 
   LEFT JOIN (
               SELECT distinct(Proj_name),BillType, COUNT(1) as billcount  FROM payment_80  where BillType='Electric'
                GROUP BY Proj_name, BillType  ) Electribill80 ON Electribill80.Proj_name = p.proj_name 
   LEFT JOIN (
               SELECT distinct(Proj_name),billtype, COUNT(1) as billcount  FROM Payment_20  where billtype='Electric'
                GROUP BY Proj_name, billtype ) Electribill20 ON Electribill20.Proj_name = p.proj_name 
   LEFT JOIN (
               SELECT distinct(Proj_name),billtype, COUNT(1) as billcount   FROM Payment  where billtype='CIVIL'
                GROUP BY Proj_name, billtype ) Civilbillpay ON Civilbillpay.Proj_name = p.proj_name 
   LEFT JOIN (
               SELECT distinct(Proj_name),billtype, COUNT(1) as billcount  FROM Payment  where billtype='CIVIL'
                GROUP BY Proj_name, billtype  ) Electribillpay ON Electribillpay.Proj_name = p.proj_name
  LEFT JOIN (
               SELECT distinct(proj_uid),item_type, COUNT(1) as billcount  FROM WorkSlipAmounts where item_type='WorkSlip'
                GROUP BY proj_uid, item_type ) CivilWorkslip ON CivilWorkslip.proj_uid = p.proj_uid
   LEFT JOIN (
               SELECT distinct(proj_uid),item_type, COUNT(1) as billcount  FROM WorkSlipAmounts  where item_type='ElecWorkSlip'
                GROUP BY proj_uid, item_type) ElectriWorkslip ON ElectriWorkslip.proj_uid = p.proj_uid
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/pM6pw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pM6pw.png" alt="enter image description here"></a></p>
  
  <p>Please help me out .
  Thank you so much </p>