注册 登录
编程论坛 SQL Server论坛

谁能解决这个存储过程的问题!!

wrcyl 发布于 2008-08-24 13:26, 1019 次点击
谁能解决这个存储过程的问题!!
这个问题实在是太搞死人了,弄了好久都没有解决
真的是找到的地方

CREATE PROCEDURE wrcyl_newscount
@w_tj bit,
@w_title varchar(50),
@w_faid int,
@w_allid varchar(50)
 AS
set nocount on
declare @w_str varchar(200);
--set @w_allid='0,1'
set  @w_str=' select count(id) from [w_news] where id>0'
 if @w_tj=1
    begin
         set @w_str=@w_str+' and n_tj=1'
   end
   if @w_faid<>0
     begin
      set @w_str=@w_str+' and n_faid='+ltrim(str(@w_faid))
    end
  if @w_allid<>null and  @w_allid<>'' and @w_allid<>'null'
    begin
     set @w_str=@w_str+' and n_allid like ''%'+ltrim(str(@w_allid+))'%'''
    end
  if @w_title<>null and @w_title<>'' and @w_title<>'null'
    begin
     set  @w_str=@w_str+' and n_title like ''%'+ltrim(str(@w_title))+'%'''
    end
--select count(id) from [w_news] where id>0 and n_allid like '%'+@w_allid+'%'
--set  @w_str=' select count(id) from [w_news] where n_allid like ''%'+@w_allid+'%'''
exec(@w_str)
--select @@w_str
GO


只要@w_allid 里面出现了除数字以外的其它字符就会出错
为什么????
它明明是varchar 型的啊!!!
5 回复
#2
wrcyl2008-08-24 13:26
这个问题很急,请高手快点帮忙解决一下
这个问题很急,请高手快点帮忙解决一下
谢谢啦
#3
球球2008-08-24 15:55
str()函数是把数值型数据转换为字符型数据
#4
seiya0278482008-08-25 09:03
你把varchar改成nvarchar试一试看看
#5
happynight2008-08-25 10:50
报什么错 贴上来
#6
wrcyl2008-08-25 13:02
还是球球厉害
str()把这个东西去掉就搞定了
谢谢啦

[[it] 本帖最后由 wrcyl 于 2008-8-25 13:05 编辑 [/it]]
1