打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
SQL Server多条件查询的实现

SQL Server多条件查询的实现

2010-11-09 15:18 佚名 互联网 我要评论(0) 字号:T | T

想要在SQL Server数据库中实现多条件查询,通过一个存储过程就可以实现,下面就让我们来了解一下该存储过程的写法。

AD:2013云计算架构师峰会超低价抢票中

SQL Server多条件查询我们经常会用到,下面就教您如何使用存储过程实现SQL Server多条件查询,希望对您学习SQL Server多条件查询方面有所帮助。

/*查询资讯类别列表*/
IF EXISTS (SELECT name FROM sysobjects
         WHERE name = 'get_list_newscate' AND type = 'P')
   DROP PROCEDURE get_list_newscate
GO
create proc get_list_newscate
@newscate_pid int=null,
@newscate_depth int=null,
@newscate_language int=null
as
select * from [news category] where 1=1
and (@newscate_pid is null or newscate_pid=@newscate_pid)
and (@newscate_depth is null or newscate_depth=@newscate_depth)
and (@newscate_language is null or newscate_language=@newscate_language)
order by newscate_orderid

此存储过程可以实现SQL Server多条件查询。

可以用于网站高级检索的功能

查询条件默认为null
程序中值类型不能为null可以在类型后加一个?这样就可以null
比如:int i=null 错误 int? i=null正确

where 1=1是为了当查询条件都不需要用到时就查询全部数据

【编辑推荐】

SQL Server跨服务器查询

SQL Server资源锁模式大全

sql server查询字段详细信息

sql server查询平均值的实现

SQL Server FROM子句的语法

【责任编辑:段燃 TEL:(010)68476606】
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
hibernate 自增 IDENTITY
SQL Server使用检查约束来验证数据实战演示
socket网络编程快速上手(二)——细节问题(5)(完结篇)
MySQL的开发必会的sql语句
SQL FOREIGN KEY 约束
SQL Server经典面试题之一
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服