<legend id='BjYmM'><style id='BjYmM'><dir id='BjYmM'><q id='BjYmM'></q></dir></style></legend>

    <small id='BjYmM'></small><noframes id='BjYmM'>

        <bdo id='BjYmM'></bdo><ul id='BjYmM'></ul>
      <tfoot id='BjYmM'></tfoot>
      <i id='BjYmM'><tr id='BjYmM'><dt id='BjYmM'><q id='BjYmM'><span id='BjYmM'><b id='BjYmM'><form id='BjYmM'><ins id='BjYmM'></ins><ul id='BjYmM'></ul><sub id='BjYmM'></sub></form><legend id='BjYmM'></legend><bdo id='BjYmM'><pre id='BjYmM'><center id='BjYmM'></center></pre></bdo></b><th id='BjYmM'></th></span></q></dt></tr></i><div id='BjYmM'><tfoot id='BjYmM'></tfoot><dl id='BjYmM'><fieldset id='BjYmM'></fieldset></dl></div>

      使用带有存储过程参数的 LIKE 运算符

      Using LIKE operator with stored procedure parameters(使用带有存储过程参数的 LIKE 运算符)
      <legend id='ckJb7'><style id='ckJb7'><dir id='ckJb7'><q id='ckJb7'></q></dir></style></legend>

          <small id='ckJb7'></small><noframes id='ckJb7'>

            <tbody id='ckJb7'></tbody>

          <tfoot id='ckJb7'></tfoot>

          • <bdo id='ckJb7'></bdo><ul id='ckJb7'></ul>
            <i id='ckJb7'><tr id='ckJb7'><dt id='ckJb7'><q id='ckJb7'><span id='ckJb7'><b id='ckJb7'><form id='ckJb7'><ins id='ckJb7'></ins><ul id='ckJb7'></ul><sub id='ckJb7'></sub></form><legend id='ckJb7'></legend><bdo id='ckJb7'><pre id='ckJb7'><center id='ckJb7'></center></pre></bdo></b><th id='ckJb7'></th></span></q></dt></tr></i><div id='ckJb7'><tfoot id='ckJb7'></tfoot><dl id='ckJb7'><fieldset id='ckJb7'></fieldset></dl></div>
                本文介绍了使用带有存储过程参数的 LIKE 运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个存储过程,它使用 LIKE 运算符在其他一些参数中搜索卡车位置

                I have a stored procedure that uses the LIKE operator to search for a truck location among some other parameters

                   @location nchar(20),
                   @time time,
                   @date date
                AS
                   select 
                       DonationsTruck.VechileId, Phone, Location, [Date], [Time]
                   from 
                       Vechile, DonationsTruck
                    where 
                       Vechile.VechileId = DonationsTruck.VechileId
                       and (((Location like '%'+@location+'%') or (Location like '%'+@location) or (Location like @location+'%') ) or [Date]=@date or [Time] = @time)
                

                我将其他参数设为空并仅按位置搜索,但即使我使用了位置的全名,它也始终不返回任何结果

                I null the other parameters and search by location only but it always returns no results even when I used the full name of the location

                推荐答案

                @location nchar(20) 的数据类型应该是 @location nvarchar(20),因为nChar 有固定长度(用空格填充).
                如果 Location 也是 nchar,则您必须对其进行转换:

                Your datatype for @location nchar(20) should be @location nvarchar(20), since nChar has a fixed length (filled with Spaces).
                If Location is nchar too you will have to convert it:

                 ... Cast(Location as nVarchar(200)) like '%'+@location+'%' ...   
                

                要使用和 AND 条件启用可为空参数,只需使用 IsNull 或 Coalesce 进行比较,这在您使用 OR 的示例中不需要.

                To enable nullable parameters with and AND condition just use IsNull or Coalesce for comparison, which is not needed in your example using OR.

                例如如果您想比较位置和日期和时间.

                e.g. if you would like to compare for Location AND Date and Time.

                @location nchar(20),
                @time time,
                @date date
                as
                select DonationsTruck.VechileId, Phone, Location, [Date], [Time]
                from Vechile, DonationsTruck
                where Vechile.VechileId = DonationsTruck.VechileId
                and (((Location like '%'+IsNull(@location,Location)+'%')) and [Date]=IsNUll(@date,date) and [Time] = IsNull(@time,Time))
                

                这篇关于使用带有存储过程参数的 LIKE 运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Accessing another user#39;s table within an Oracle Stored Procedure(在 Oracle 存储过程中访问另一个用户的表)
                Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32)(超出最大存储过程、函数、触发器或视图嵌套级别(限制 32))
                How to View Oracle Stored Procedure using SQLPlus?(如何使用 SQLPlus 查看 Oracle 存储过程?)
                How to debug stored procedure in VS 2015?(如何在 VS 2015 中调试存储过程?)
                How to Pass Java List of Objects to Oracle Stored Procedure Using MyBatis?(如何使用 MyBatis 将 Java 对象列表传递给 Oracle 存储过程?)
                Set the variable result, from query(设置变量结果,来自查询)
                • <legend id='i99RM'><style id='i99RM'><dir id='i99RM'><q id='i99RM'></q></dir></style></legend>
                    <tbody id='i99RM'></tbody>
                  • <bdo id='i99RM'></bdo><ul id='i99RM'></ul>
                    <i id='i99RM'><tr id='i99RM'><dt id='i99RM'><q id='i99RM'><span id='i99RM'><b id='i99RM'><form id='i99RM'><ins id='i99RM'></ins><ul id='i99RM'></ul><sub id='i99RM'></sub></form><legend id='i99RM'></legend><bdo id='i99RM'><pre id='i99RM'><center id='i99RM'></center></pre></bdo></b><th id='i99RM'></th></span></q></dt></tr></i><div id='i99RM'><tfoot id='i99RM'></tfoot><dl id='i99RM'><fieldset id='i99RM'></fieldset></dl></div>

                    <tfoot id='i99RM'></tfoot>
                      • <small id='i99RM'></small><noframes id='i99RM'>