首页 何问起 前端特效 htbtn-4 闪电 使用方法

在SQL存储过程中给条件变量加上单引号

在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

posted @ 2016-05-12 08:04  roucheng  阅读(5019)  评论(0编辑  收藏  举报