sql 語句加判斷規則

2021-06-26 09:24:35 字數 688 閱讀 7361

假設現在 傳進來2個引數 isput ,isplus 值都為 1,0

語句大概如下:

select * from table  t where ( (isput =0 and isplus=0 ) or (isput =1 and isplus=1 and t.fmodifyno is not null)  or (isput =1 and isplus=0 and t.fmodifyno is not null and t.fmodifyno not like 'cg%' )  or (isput =0 and isplus=1 and t.fmodifyno  like 'cg%'))

如果 isput =0,isplus=0 就會進入執行(isput =0 and isplus=0 )

如果 isput =1,isplus=1 就會進入執行(isput =1 and isplus=1 and t.fmodifyno is not null)

如果 isput =1,isplus=0 就會進入執行(isput =1 and isplus=0 and t.fmodifyno is not null and t.fmodifyno not like 'cg%' ) 

如果 isput =0,isplus=1 就會進入執行(isput =0 and isplus=1 and t.fmodifyno  like 'cg%')

這樣就可以實現判斷執行

分頁加搜尋sql語句

分頁儲存過程 if object id pro page p is notnull drop proc pro stu gocreate procedure pro stu pageindex int,pagesize int as declare startrow int,endrow int s...

簡單學習SQL語句規則

create database db2 建立資料夾,名字叫db2 create database db2 default charset utf8 建立資料夾,utf 8格式 show databases 顯示資料夾 drop database db1 刪除資料夾 use db2 使用哪個資料夾 s...

為什麼SQL語句加 1 1

是為了鏈結下面的查詢條件條件,也或者是替換沒有查詢條件的語句。比如 要把檢索條件作為乙個引數傳遞給sql,那麼,當這個檢索語句不存在的話就可以給它賦值為1 1.這樣就避免了sql出錯,也就可以把加條件的sql和不加條件的sql合二為一。這個就是為了方便sql條件的拼接,在 where 和 and 的...