當前位置:首頁 » 編程語言 » 多sql

多sql

發布時間: 2025-03-13 16:09:04

sql多條件查詢幾種實現方法詳細介紹

SQL 多條件查詢
以後我們做多條件查詢,一種是排列結合,另一種是動態拼接SQL
如:我們要有兩個條件,一個日期@addDate,一個是@name
第一種寫法是
if (@addDate is not null) and (@name <> '')select * from table where addDate = @addDate and name = @nameelse if (@addDate is not null) and (@name ='')select * from table where addDate = @addDate else if(@addDate is null) and (@name <> '')select * from table where and name = @nameelse if(@addDate is null) and (@name = '')select * from table
第二種就是動態組成SQL,通過exec來執行,我就不寫。
昨天我想到一種辦法
select * from table where (addDate = @addDate or @addDate is null) and (name = @name or @name = '')
結果一調試,成功。
一點想法,有更好方法的,請指教!~
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!您可能感興趣的文章:
SqlServer使用 case when 解決多條件模糊查詢問題SqlServer 巧妙解決多條件組合查詢linq to sql 中,如何解決多條件查詢問題,答案,用表達式樹! (下)linq to sql中,如何解決多條件查詢問題,答案,用表達式樹!MySQL中使用case when 語句實現多條件查詢的方法sql 多條件組合查詢,並根據指定類別找出所有最小子類別的SQL語句備忘 標簽 SQL 多條件 查詢

熱點內容
我的世界2b2t伺服器海上農場 發布:2025-03-13 19:25:33 瀏覽:991
人工智慧安卓主板哪個好 發布:2025-03-13 19:15:16 瀏覽:235
android系統程序 發布:2025-03-13 19:12:15 瀏覽:36
如何修改樂視賬號密碼 發布:2025-03-13 18:56:12 瀏覽:970
c編程書籍 發布:2025-03-13 18:51:49 瀏覽:449
我的世界伺服器在哪玩 發布:2025-03-13 18:41:51 瀏覽:385
APK反編譯查看密碼加密方式 發布:2025-03-13 18:36:32 瀏覽:452
切沙子的聲音解壓視頻 發布:2025-03-13 18:15:59 瀏覽:469
為什麼安卓手機直播音效不好 發布:2025-03-13 18:15:53 瀏覽:671
javahttps證書 發布:2025-03-13 18:10:23 瀏覽:558