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

解决方案 »

  1.   

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

  2.   

    declare @表 sysname
    exec('insert into '+@表+'(cVouchType,cVouchID,dVouchDate,cDeptCode,cCoVouchID,cOperator,cCheckMan,iID,cDwCode,cexch_name,cflag)
    select case when io_flag>=6 then substring(io_flag,1,5) else io_flag 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.   

    一楼看错了吧? "如果取出io_flag的值大于6",不是len不过,楼主要取 substring(io_flag,1,5) ,似乎又应该是 len 的理解才对