int c;select Num ,name,type,c*ammout from jzy1308a12v其中c是自定义的一个整型变量,怎样才能把C的值传入到这条sql 语句中?
C# SQL

解决方案 »

  1.   

    string.format(“select Num ,name,type,{0} from jzy1308a12v“,c*ammout)
      

  2.   

    用string.Format
    string strUpdate = string.Format(@" update empattenceaudit set auditstate=1 where Yearmonth='{0}' and empid={1} and
                    exists (select 1 from empattenceaudit where Yearmonth='{0}' and companyid={2} and coalesce(auditstate,0)=1 )",
                    strYearMonth, EmpId, strCompany);
    或者字符串直接拼接
     string sqlgz = @"select SHEETID from TBLPAYLISTSHEET 
                where YEARMONTH='" + findYearMonth + "' and WHETHERIMPORT=1";
      

  3.   

    string sql="select Num ,name,type,"+"'+c.ToString()+'"+"*ammout from jzy1308a12v";
      

  4.   

    select Num ,name,type,"+c+"*ammout from jzy1308a12v
      

  5.   

    select Num ,name,type,"+c+"*ammout from jzy1308a12v
      

  6.   

    declare @C INT
    EXEC('select '+@C+'=count(*) from '+@TableName)