exec('insert into '+@表+'(cVouchType,cVouchID,dVouchDate,cDeptCode,cCoVouchID,cOperator,cCheckMan,iID,cDwCode,cexch_name,cflag)
select io_flag,Bill_num,Bill_date,isnull(ltrim(rtrim(dept_id)),'''') ,Cor_billnum,bill_empid,Aud_Empid,ordercode ,case IO_flag when 0 then 48 else 49 end as my,''人民币'',''AP'' from 表2)

解决方案 »

  1.   

    最后少了个引号:
    exec('insert into '+@表+'(cVouchType,cVouchID,dVouchDate,cDeptCode,cCoVouchID,cOperator,cCheckMan,iID,cDwCode,cexch_name,cflag)
    select io_flag,Bill_num,Bill_date,isnull(ltrim(rtrim(dept_id)),'''') ,Cor_billnum,bill_empid,Aud_Empid,ordercode ,case IO_flag when 0 then 48 else 49 end as my,''人民币'',''AP'' from 表2')
      

  2.   

    exec('insert into '+@表+'(cVouchType,cVouchID,dVouchDate,cDeptCode,cCoVouchID,cOperator,cCheckMan,iID,cDwCode,cexch_name,cflag)
    select case io_flag when 0 then 48 else 49 end,Bill_num,Bill_date,nullif(ltrim(rtrim(dept_id)),'''') ,Cor_billnum,bill_empid,Aud_Empid,ordercode ,IO_flag as my,''人民币'',''AP'' from 表2)
      

  3.   

    exec('insert into '+@表+'(cVouchType,cVouchID,dVouchDate,cDeptCode,cCoVouchID,cOperator,cCheckMan,iID,cDwCode,cexch_name,cflag)
    select case io_flag when 0 then 48 else 49 end,
    ,Bill_num,Bill_date,nullif(ltrim(rtrim(dept_id)),'''') ,Cor_billnum,bill_empid,Aud_Empid,ordercode ,IO_flag as my,''人民币'',''AP'' from 表2)
      

  4.   

    --如果io_flag 就0,1两种取值
    exec('insert into '+@表+'(cVouchType,cVouchID,dVouchDate,cDeptCode,cCoVouchID,cOperator,cCheckMan,iID,cDwCode,cexch_name,cflag)
    select io_flag+48,Bill_num,Bill_date,nullif(ltrim(rtrim(dept_id)),'''') ,Cor_billnum,bill_empid,Aud_Empid,ordercode ,IO_flag as my,''人民币'',''AP'' from 表2')