本文介紹了SQL - 過(guò)濾器值為空時(shí)全選的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
我的 ASP.net Web 應(yīng)用程序中有一個(gè) SQL 查詢,如下所示:
I have a SQL query in my ASP.net web app that looks like this:
SELECT * FROM [Records] WHERE ([title] LIKE '%' + @title + '%')
@title,當(dāng)然是頁(yè)面上一個(gè)文本框的值.
@title, of course, is the value of a text box on the page.
我的問(wèn)題是,為什么當(dāng)文本框?yàn)榭諘r(shí),這不返回任何內(nèi)容?我怎樣才能讓它返回一切,就像邏輯告訴我它應(yīng)該那樣?
My question is, why, when the text box is empty, does this return nothing? And how can I make it return everything, like logic tells me it ought to?
推薦答案
SELECT * FROM [Records]
WHERE @title IS NULL OR LEN(@Title) = 0 OR ([title] LIKE '%' + @title + '%')
這篇關(guān)于SQL - 過(guò)濾器值為空時(shí)全選的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!