根据商品名称、价格区间检索商品的SQL语句
2024-10-09 04:12:46
如果名称和价格为空会检索出所有的数据
1 select * from TblProduct
2 where (@proName='' or chvProName like '%'+@proName+'%')
3 and (@minPrice='' or mnyProPrice>=@minPrice)
4 and (@maxPrice='' or mnyProPrice<=@maxPrice);
5
6--下面将参数替换成字符串
7 --测试
8 select * from TblProduct
9 where (''='' or chvProName like '%'+''+'%')
10 and (''='' or mnyProPrice>=null)
11 and (''='' or mnyProPrice<=null);
--检索出所有的商品
注:' ' is null 返回的false
--如果更改成下面代码:会报【从数据类型 varchar 转换为 numeric 时出错。】的错
select * from TblProduct
where (' '=' ' or chvProName like '%'+''+'%')
and (' ' is null or mnyProPrice>='')
and (' ' is null or mnyProPrice<='');
如果将mnyProPrice>='' 改为mnyProPrice>=null则不会报错,但因为条件不满足,检索不到任何数据
最新文章
- lua命令行编译
- 使用NetBeans、Eclipse阅读JDK源码
- 实现在Android 进程和线程
- Java初学(三)
- intellij 2016注册
- Navicat 11使用技巧
- (整理)C#实现UDP广播
- 亚马逊 在线测试题目 amazon (变种的)三叉树的最近公共祖先问题
- IOS 调用系统发邮件Api
- Vasya and String(尺取法)
- Linux下NAT模式和桥接模式的网络配置
- idea报错:[2016-08-31 09:20:10,763] Artifact xxx:war exploded: Error during artifact deployment.
- centos 7 忘记密码
- scala中to和util操作
- 纯js倒计时效果(交流加群:452892873)(本群每天都更新学习资料)
- mysql优化概述2
- CSS&;&;xpath
- 深拷贝(deep clone)与浅拷贝(shallow clone)
- IIS自定义404错误不能生效的原因
- 前端开发 - HTML - 简介
热门文章
- 描述一下C#中索引器的实现过程,是否只能根据数字进行索引?
- CKEditor Html Helpers for ASP.NET MVC3 Razor/WebForms Views
- JavaScript 模板引擎实现原理解析
- 快速入门系列--WebAPI--03框架你值得拥有
- Android入门(三)Activity-生命周期与启动模式
- Aspect Oriented Programming
- 【博客美化】06.添加QQ交谈链接
- 深入理解CSS中的空白符和换行
- SQL*Loader之CASE1
- Unity3D 中的三个Update()方法