存储过程定义了以下变量:
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个字符,后面的字符都没了,怎么回事?
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个字符,后面的字符都没了,怎么回事?
再说了 从后台开发这个思路上说 你这个变量好象也太长了
一般来说VCHAR 都是申请连续物理空间,
估计太长了很难申请到??可能是 就给你按一定规则拆分了。
这个在 操作层面也是很合理的。
@IM varchar(10)
@IMType varchar(2)
@length varchar(1)都是e文的再强调一下的是insert语句在分析器中执行一点问题都没有。但在存储过程中就出问题了。
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
这里有问题,应该是isnull(i.cont,'''')=isnull(i1.cont,'''')