variable in C# SQL Query not working : So I have a loop in which I grab certain ID's to make a call in a database. There are 2 variable within the query. The first one works fine but the second one returns nothing. I have tested it a lot and know that the correct value is coming through to the query. Not sure what I am doing wrong here. I replace the variable with a hard coded value that I know is returning and it works fine. Here is my code:


        SqlDataAdapter d8;

        d8 = new SqlDataAdapter("select SUM(CAST(AMOUNT AS BIGINT)) AS NEW_AMOUNT 
        FROM ddb_proc_log_base where ( PROVID = "+docId+" AND CHART_STATUS = 90 
        AND YEAR(PLDATE) = 2016 AND CLASS = 2 AND ORD = " + defer + ") OR (ORD = " 
        + defer + " AND PROVID = " + this.getDocHygDS.Tables[0].Rows[t]["HYG_ID"] 
        + " AND CHART_STATUS = 90 AND YEAR(PLDATE) = 2016 AND CLASS = 2)", conn3);
        
        cmdBuilder5 = new SqlCommandBuilder(d8);
        d8.Fill(this.balances);
                                