zoukankan      html  css  js  c++  java
  • 在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

  • 相关阅读:
    防抖函数
    video.js汉化
    vscode 设置
    webpack配置
    寄生组合继承
    数组排序
    操作节点的方法
    vscde软件
    vue目录详解
    前端
  • 原文地址:https://www.cnblogs.com/roucheng/p/sqldanyinhao.html
Copyright © 2011-2022 走看看