Remove the single quote on the line indicated below:cmdS2 = new SqlCommand("SELECT TOP 1 SupplierId, Supplier,"
+ " SUM(TotalValue) FROM view_test WHERE YEAR(dDate)='"
+ pRefYear.ToString() + "' AND " + strR +
"Id IN(" + strId
+ ")AND SupplierId <> '" -- <== Remove the single quote shown in red
+ strSupplierId[0]
+ "AND SupplierId <> '6335'"
+ "GROUP BY SupplierId, Supplier ORDER BY SUM(TotalValue) DESC", conS2);Also, put spaces so that there is a space between the supplierId and the AND that follows it; similarly, before GROUP BY etc.