存储过程定义了以下变量:
declare @sql varchar(1000)set @sql='insert tmp select * from (select  distinct i.* from zd z,im i where (charindex(i.from,z.'+@IM+')>0 or charindex(i.to,z.'+@IM+')>0) and len(z.'+@IM+')>'+@length+' and i.imtype='+@IMType+') i1 where not exists(select * from imtmp i where i.ac=i1.ac and i.ime=i1.time and isnull(i.cont,'''''')=isnull(i1.cont,'''''') and i.dest=i1.dest and i.from=i1.from and i.type=i1.type and i.src=i1.src and i.to=i1.to)'以上这段insert代码在分析器中执行一点问题都没有,但将其变为存储过程就发现字符串被截断了。调试时发现@sql只有456个字符,后面的字符都没了,怎么回事?

解决方案 »

  1.   

    不过我看这个方法到是能测出 你的服务器上合理的变量长度
    再说了 从后台开发这个思路上说 你这个变量好象也太长了
    一般来说VCHAR  都是申请连续物理空间,
    估计太长了很难申请到??可能是 就给你按一定规则拆分了。
    这个在 操作层面也是很合理的。
      

  2.   

    定义为varchar(8000), 然后一段一段加上字符串试试,看错误在哪,太长了,看不过来,或者你把字符串拿到查询分析器里面看看颜色,应该很明显
      

  3.   

    定义的变量是这样的
    @IM varchar(10)
    @IMType varchar(2)
    @length varchar(1)都是e文的再强调一下的是insert语句在分析器中执行一点问题都没有。但在存储过程中就出问题了。
      

  4.   

    也试过定义了varchar(8000),结果还是一样,求助。
      

  5.   

    to playwarcraft(时间就像乳沟,挤挤还是有的) 存储过程很简单,就是插入没有重复的记录:
    CREATE PROCEDURE sp_IM
    @IM varchar(10),
    @IMType varchar(2),
    @length varchar(1)
    AS
    declare @sql varchar(8000)set @sql='insert tmp select * from (select  distinct i.* from zd z,im i where (charindex(i.from,z.'+@IM+')>0 or charindex(i.to,z.'+@IM+')>0) and len(z.'+@IM+')>'+@length+' and i.type='+@IMType+') i1 where not exists(select * from tmp i where i.ac=i1.ac and i.time=i1.time and isnull(i.cont,'''''')=isnull(i1.cont,'''''') and i.dest=i1.dest and i.from=i1.from and i.type=i1.type and i.src=i1.src and i.to=i1.to)'
    exec(@sql)
    GO
      

  6.   

    isnull(i.cont,'''''')=isnull(i1.cont,'''''')
    这里有问题,应该是isnull(i.cont,'''')=isnull(i1.cont,'''')