在SQL存储过程中给条件变量加上单引号,不加语句就会出问题,以下就是在存储过程中将条件where设置成了动态变化的,给where赋完值再和前面的语句拼接,再execute(SQL)

set @where= '(DATEDIFF(day,'''+CONVERT(varchar(100), @d_start, 23)+''',sdate)>=0 and DATEDIFF(day,'''+CONVERT(varchar(100), @d_end, 23)+''',sdate)<=0) and '  
    +'  shopid='''+@shopid+''' and  VenderID in '  
    +' (select vender from tableB where vendertype=''类型'' and shopid='''+@shopid+''')'  

-- 何问起 hovertree.com 

@d_start   @d_end,

@shopid  

 

这三个都是调用存储过程传进来的参数,要将这些与varchar类型的拼接在一起就要用每边3个单引号+变量, eg: where shopid='''+@shopid+''' 这样写才可以。

 

推荐:http://www.cnblogs.com/roucheng/p/3541165.html

相关文章:

  • 2021-06-24
  • 2021-09-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-08
  • 2021-12-19
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案