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