在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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM