zoukankan      html  css  js  c++  java
  • 一个不大注意的存储过程的小细节。

    看下面这个存储过程
    create proc pGetInforArticleDataBySearch
    @autoTypeCode        as varchar(6),
    @autoFittingCode     as varchar(3),
    @keyword            as nvarchar(10)
    as
    begin
    set @autoTypeCode='%'+@autoTypeCode+'%'
    set @autoFittingCode='%'+@autoFittingCode+'%'
    set @keyword='%'+@keyword+'%'
    SELECT * FROM dbo.vinfoArticle
    where autoTypeCode like @autoTypeCode and autoFittingCode like @autoFittingCode and title like @keyword
    end
    我们可以看到,入参重新设置为like的使用值,这个时候,如果@autoTypeCode的入参值长度为6位的时候,例如:100001,set @autoTypeCode='%'+@autoTypeCode+'%'以后@autoTypeCode就变成了%10000,自然就匹配不到了。
    所以我们必须把@autoTypeCode的长度设置的长一些,不能和数据库字段的长度相同。
    例如:
    create proc pGetInforArticleDataBySearch
    @autoTypeCode        as varchar(10),
    @autoFittingCode     as varchar(10),
    @keyword            as nvarchar(12)
    as
    begin
    set @autoTypeCode='%'+@autoTypeCode+'%'
    set @autoFittingCode='%'+@autoFittingCode+'%'
    set @keyword='%'+@keyword+'%'
    SELECT * FROM dbo.vinfoArticle
    where autoTypeCode like @autoTypeCode and autoFittingCode like @autoFittingCode and title like @keyword
    end
  • 相关阅读:
    LeetCode Power of Three
    LeetCode Nim Game
    LeetCode,ugly number
    LeetCode Binary Tree Paths
    LeetCode Word Pattern
    LeetCode Bulls and Cows
    LeeCode Odd Even Linked List
    LeetCode twoSum
    549. Binary Tree Longest Consecutive Sequence II
    113. Path Sum II
  • 原文地址:https://www.cnblogs.com/ami/p/548753.html
Copyright © 2011-2022 走看看