RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
SQL Server多条件查询的实现

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

成都创新互联专业为企业提供阿瓦提网站建设、阿瓦提做网站、阿瓦提网站设计、阿瓦提网站制作等企业网站建设、网页设计与制作、阿瓦提企业网站模板建站服务,10多年阿瓦提做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

/*查询资讯类别列表*/
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子句的语法


网站栏目:SQL Server多条件查询的实现
分享网址:http://jxjierui.cn/article/djojdcd.html