sql 如何擷取時間字串然後再模糊查詢出來 5

2025-03-03 02:45:16 字數 3314 閱讀 2454

sql 如何擷取時間字串然後再模糊查詢出來

1樓:網友

declare @date varchar(40)

set @date='2011-05-16 11:33:22'

select *

from u_deposit

where convert(varchar(10),d_date,121) like '%right(convert(varchar(10),@date,112),5)+'

-測試結虛激氏果。

d# account_no worker_no d_money d_date d_type

3 323424343243413 u001 50 2011-05-16 存款。

4 323424343243414 u001 50 2011-05-16 存款。

5 323424343243414 u001 2011-05-16 存款。

6 323424343243414 u001 2011-05-16 存款。

7 323424343243414 u001 12 2011-05-16 存款。

8 323424343243413 u001 1 2011-05-16 存鉛好款。

6 行受影差散響)

2樓:網友

就是用 convert 函式, 將 日期型別, 轉換為 字元型別, 然後就可以去 like '%09-05%' 處理了。

convert 函式使段橘用如臘例握橡糰子。

select convert(varchar(30), getdate(),120)

sql 模糊查詢 但是查的是 字元「%」

3樓:網友

% 是萬用字元號,表示通配0個或多個字元。

如果你想查詢使用者裡帶 % 的資料,應該採用以下語句select * from users where username like '%[%'

希望能幫到你。

4樓:網友

使用轉義符。

select * from users where usernamelike '%/%ab' escape '/' ;

這樣能匹配到 以 %ab 結尾的資料。

5樓:網友

特殊字元 %用要加括號 [%

6樓:

你這是啥型別資料庫啊?

sqlserver資料庫中,日期的模糊查詢

7樓:依然特雷西

1、開啟sql server management studio管理工具,點選【新建查詢】,新建乙個sql書寫視窗,用於演示sql的執行。

2、獲取sqlserver中的最小日期(1900-01-01 。

3、獲取明年的今天,含時間的日期,select dateadd(year, 1, getdate())

4、獲取明年的今天距離sqlserver最小日期之間差了多少年。

5、計算sqlserver最小日期的前一天日期,不含時間。

8樓:人設不能崩無限

1、先開啟sql server資料庫並連線。

2、然後找到目標資料庫,右鍵並點選「屬性」。

3、在彈出的屬性視窗左側「選擇頁」中選擇「檔案」選項卡。

4、然後在右側窗體中即可看到相應內容了:邏輯名稱是資料檔案及日誌檔案的檔名,路徑就是其所在位置了。

9樓:匿名使用者

將資料庫中的時間欄位格式改為字串格式。

select * from t where convert(varchar,sendtime,120) like '2007-12-30%'

其中:t為資料庫的表,sendtime是資料庫中的時間欄位的欄位名。這樣就可以查詢2007-12-30的記錄了。

10樓:網友

年可以用函式year(日期)=2007

某年某月可以分開查year(日期)=2007 and month(日期)=1

或者轉換格式convert(varchar(7), 日期, 23)='2007-01'

11樓:網友

直接convert後進行等值判斷,不需要like

select * from a convert(varchar(7), 日期, 120) = '2007-01'

關於sql模糊查詢日期時間的方法?

12樓:

模糊查詢有以下三種方法:

轉成string,在用like查詢。

select * from table1 where convert(varchar,date,120) like '2006-04-01%'

select * from table1 where time between '2006-4-1 0:00:00' and '2006-4-1 24:59:59'";

3 datediff()函式。

select * from table1 where datediff(day,time,'2006-4-1')=0

第一種方法應該適用與任何資料型別;

第二種方法適用string外的型別;

第三種方法則是為date型別定製的比較實用快捷的方法。

從sql表裡擷取字串中的日期

13樓:網友

select substring(text,charindex('between',text)+9 ,10) from test

substring ( character_expression , start , length )

函式說明:substring ( '源字串' , '擷取起始位置(含該位置上的字元)' , '擷取長度' )

返回字元、binary、text 或 image 表示式的一部分。

select substring('sql_server_2008',5 ,6);

返回結果:server

14樓:太平保險展業

你是在函式里面寫還是儲存過程,如果是儲存過程,可以將該日期值放入全域性變數之中,可以在另外乙個函式中得到的。

sql 時間模糊查詢

15樓:網友

查詢12年10份的所有資料:

select * from leve where datediff(month,add_date,『2012-10-01』)=0

c符串擷取,c 字串擷取

沒理解你的具體意思,不過擷取字串可以用substring方法。先indexof查詢到死的部分的位置再擷取 string str e tws tws ui print 2013122423 picture picture string str1 str.substring 0,str.indexof ...

asp擷取字元長度,asp 擷取字串的函式怎麼寫

left 要擷取的字串,要擷取的長度 從左邊開始擷取指定長度的字元 right 要擷取的字串,要擷取的長度 從右邊開始擷取指定長度的字元 mid 要擷取的字串,開始擷取的位置,要擷取的長度 從任意位置開始擷取指定長度的字元 mid 201109110820 1,4 年 mid 20110911082...

如何獲取最後字元後面的字串sql中

sql語句可以擷取指定欄位後面的字串,以sqlserver為例,需要用到charindex函式和substring函式。如test表中有如下資料,要求截圖str欄位中逗號後邊的內容。可用如下語句 1select id,substring str,charindex str 1,len str cha...