1、proc如下:
  
  IF @ClassID =0
  SET  @SQLSTR ='SELECT * FROM (SELECT TOP '+STR(@RecordCount - @PageSize * @PageIndex)+ '  XiangMuDan.*   FROM XiangMuDan where 1=1'
  ----条件查询
  if (@xiangmuName<>null)
  --*************出错行
  select  @SQLSTR =@SQLSTR+' and XiangMuMing like ''%'+str(@xiangmuName)+'%'''   
  if (@gongyingShang<>null)
  select  @SQLSTR = @SQLSTR+' and GongYingShang like ''%'+str (@gongyingShang)+'%'''     SET @SQLSTR =@SQLSTR+' order by Created ASC)TempTable ORDER BY Created DESC'2、当@xiangmuName和@gongyingShang不为空时,Exec proc时就发生错误?

解决方案 »

  1.   


      IF @ClassID =0
      SET  @SQLSTR ='SELECT * FROM (SELECT TOP '+STR(@RecordCount - @PageSize * @PageIndex)+ '  XiangMuDan.*   FROM XiangMuDan where 1=1'
      ----条件查询
      if (@xiangmuName is not null)
      --*************出错行
      select  @SQLSTR =@SQLSTR+' and XiangMuMing like ''%'+str(@xiangmuName)+'%'''   
      if (@gongyingShang is  not null)
      select  @SQLSTR = @SQLSTR+' and GongYingShang like ''%'+str (@gongyingShang)+'%'''     SET @SQLSTR =@SQLSTR+' order by Created ASC)TempTable ORDER BY Created DESC' 判断 NULL 不能用 = <> , 要用is null  或者 is not null 
    再试一下
      

  2.   

    @xiangmuName 这种东东如果是外面传进来的参数最好不要用int
    用varchar判断的时候用
    if isnull(@xiangmuName,0)=0 --判断是否空值