在專案中,需要使用模糊查詢來查詢當天或某個時間段的資訊記錄,已知在資料庫中使用的是datetime時間型別。
方法一(用於查詢當天的某項記錄,專為date型別定製的快捷的方法):
方法二(注意,最好在引數中設定%,否則容易報錯):string sql = "select count(*) from studentbind*****typeentity where isuse ='1' and
datediff(day,timetamp,getdate())=0 and exammodel='練習模式' ";
方法三(適用於任何資料型別):sqlparameter paras = new sqlparameter ;
string sql = "select count(*) from studentbind*****typeentity where isuse ='1' and
timetamp like @date and exammodel='練習模式' and ip like @ip";
方法四(適用於除string外的型別):string sql = "select * from scoreentity where score>@score and convert(varchar,timetamp,120)
like '@date%' and exammodel='練習模式'
select * from table1 wheretimetamp between '2018-12-29 0:00:00' and '2018-12-29 24:59:59'";
SQL模糊查詢語句
sql模糊查詢的語法為 select column from table where column like pattern sql提供了四種匹配模式 1.表示任意0個或多個字元。如下語句 select from user where name like 三 將會把name為 張三 三腳貓 唐三藏 ...
SQL模糊查詢語句
sql模糊查詢語句 一般模糊語句語法如下 select 字段 from 表 where 某欄位 like 條件其中關於條件,sql提供了四種匹配模式 1 表示任意0個或多個字元。可匹配任意型別和長度的字元,有些情況下若是中文,請使用兩個百分號 表示。select from user where u ...
SQL 的查詢語句,模糊查詢
一般模糊語句如下 select 字段 from 表 where 某欄位 like 條件 其中關於條件,sql提供了四種匹配模式 1,表示任意0個或多個字元。可匹配任意型別和長度的字元,有些情況下若是中文,請使用兩個百分號 表示。比如 select from user where u name lik...