SQL Server多條件查詢的實(shí)現(xiàn)
SQL Server多條件查詢我們經(jīng)常會(huì)用到,下面就教您如何使用存儲(chǔ)過程實(shí)現(xiàn)SQL Server多條件查詢,希望對(duì)您學(xué)習(xí)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
此存儲(chǔ)過程可以實(shí)現(xiàn)SQL Server多條件查詢。
可以用于網(wǎng)站高級(jí)檢索的功能
查詢條件默認(rèn)為null
程序中值類型不能為null可以在類型后加一個(gè)?這樣就可以null
比如:int i=null 錯(cuò)誤 int? i=null正確
where 1=1是為了當(dāng)查詢條件都不需要用到時(shí)就查詢?nèi)繑?shù)據(jù)
【編輯推薦】




















