title: This query actually works in C#, but does not work in SQL Server when executed
body: <p>This way actually work in C#. But it does not work in SQL Server when executed:</p>
  <pre><code>Select 
      t3.MNAME + cast(t3.N as nvarchar) as 'کد دسته بندي',
      t3.NAME as 'شرح دسته',
      sum(case when t1.DT = 1 then t1.N1 - t1.N2 else 0 end) as 'خريد',
      sum(case when t1.DT = 8 then t1.N1 - t1.N2 else 0 end) as 'برگشت خريد',
      '' as 'حواله شعب',
      '' as 'برگشت شعب',
      '' as 'فروش',
      sum(case when t1.DT = 9 then t1.N1 - t1.N2 else 0 end) as 'برگشت فروش',
      sum(case when t1.DT = 10 then t1.N1 - t1.N2 else 0 end) as 'ت کاردکس',
      sum(N1 - N2) as 'موجودي',
      sum(case when t1.DT = 4 then t1.N1 - t1.N2 else 0 end) as 'ح شعب',
      sum(case when t1.DT = 5 then t1.N1 - t1.N2 else 0 end) as 'ح ت شعب',
      sum(case when t1.DT = 6 then t1.N1 - t1.N2 else 0 end) as 'ب شعب',
      sum(case when t1.DT = 7 then t1.N1 - t1.N2 else 0 end) as 'ب ت شعب',
      sum(case when t1.DT = 2 then t1.N1 - t1.N2 else 0 end) as 'ح ت فروش',
      sum(case when t1.DT = 3 then t1.N1 - t1.N2 else 0 end) as 'فروش جزئي',
      sum(case when t1.DT = 12 then t1.N1 - t1.N2 else 0 end) as 'فروش عادي',
      sum(case when t1.DT = 11 then t1.N1 - t1.N2 else 0 end) as 'برگشت فروش تعدادي' 
  From 
      BC as t1, _TBS_TYPE as t3   
  Where 
      substring(t1.BARCODE, 1, 1) = t3.MNAME 
      and substring(t1.BARCODE, 2, 1) = cast(t3.N as nvarchar)  
      and t3.MNAME + cast(t3.N as nvarchar) and t3.NAME  
  group by 
      t3.MNAME, t3.N, t3.NAME 
  order by 
      2, 3
  </code></pre>
  <p>Error :</p>
  <blockquote>
  <p>An expression of non-boolean type specified in a context where a condition is expected, near 'and'.</p>
  </blockquote>