偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

教您SQL SERVER查詢時(shí)間條件式寫法

數(shù)據(jù)庫(kù) SQL Server
學(xué)習(xí)SQL數(shù)據(jù)庫(kù),查詢必然是重中之重,下面就將為您詳細(xì)介紹SQL SERVER查詢時(shí)間條件式寫法,希望對(duì)您有所啟迪。

查詢時(shí)SQL SERVER數(shù)據(jù)庫(kù)的核心,下面就將教您SQL SERVER查詢時(shí)間條件式寫法,供您參考,希望對(duì)您更好學(xué)習(xí)SQL SERVER查詢能夠有所幫助。

如下表:

tid   tname tdate
1      張三        2009-10-29 19:04:50
2      李四        2006-11-12 11:04:50
3      王五        2007-6-11
4      陳六        2007-8-26 12:04:50
5      小二        2009-11-28

下面開始做各種時(shí)間查詢:注意:避免在WHERE條件式中對(duì)字段做運(yùn)算,比如convert(char(10),tdate,120)

select tname from tt Where tdate='2007-06-11' --當(dāng)時(shí)間段值為2007-06-11 00:00:00.000時(shí),此條件式成立

--select tname 時(shí)間值沒有 from tt Where tdate='2007-08-26' --時(shí)間段值為2007-08-26 12:04:50.000,此條件式不成立,時(shí)間值不同,這樣找不到當(dāng)天值
select tname 查找當(dāng)天時(shí)間 from tt Where tdate between '2007-08-26 00:00:00' and '2007-08-26 23:59:59'
--select tname 今天的值 from tt Where tdate =getdate() --不行,因?yàn)镾QL會(huì)默認(rèn)當(dāng)天起點(diǎn)是00:00:00開始,

select tname 今天的值方式一 from tt Where tdate between convert(char(10),getdate(),120) and convert(char(10),getdate(),120)+' 23:59:59'
select tname 今天的值方式二 from tt Where tdate >= convert(char(10),getdate(),120) and tdate<convert(char(10),getdate()+1,120)

--select tname from tt Where left(tdate,10)='2007-06-11' --

--select tname from tt Where convert(char(10),tdate,120)='2007-06-11' --查找當(dāng)天值,可以用,但效率低

--select tname aa from tt Where convert(char(10),tdate,120)='2007-08-26' --查找當(dāng)天值,可以用,但如果條件式后面為‘2007-8-26’則不行.因?yàn)閏har(10)限定十位

--select tname 時(shí)間 from tt Where tdate Like '2007-08-26%' --不可用,找不到記錄
--select tname 時(shí)間段 from tt Where tdate between '2007-06-11' and '2007-09-12'

查找時(shí)間段也是一樣的,如:

select tname 查找2007年6月11號(hào)到8月26的記錄 From tt Where tdate >='2007-06-11' and tdate<= '2007-08-26 23:59:59'
 

以上就是SQL SERVER查詢時(shí)間條件式寫法。

 

【編輯推薦】

初級(jí)sql select語(yǔ)法

sql server死鎖的檢測(cè)方法

SQL SERVER字段類型的說(shuō)明

SQL Server安全解析

保護(hù)sql server安全的措施

責(zé)任編輯:段燃 來(lái)源: 互聯(lián)網(wǎng)
相關(guān)推薦

2010-11-09 13:28:13

SQL SERVER查

2010-09-28 11:28:40

SQL字段屬性

2010-09-27 16:48:07

sql server時(shí)

2010-09-27 16:32:46

SQL Server日

2010-09-14 13:22:51

sql server備

2010-10-21 14:06:22

定義SQL Serve

2010-09-26 13:56:43

SQL遠(yuǎn)程查詢

2010-09-25 09:34:05

sql server主

2010-10-21 16:59:37

SQL Server創(chuàng)

2010-10-19 16:58:34

SQL Server日

2010-10-21 16:59:37

SQL Server創(chuàng)

2010-09-16 15:48:03

SQL Server系

2010-10-13 16:49:56

MySql查詢時(shí)間段

2010-09-07 09:45:48

SQL語(yǔ)句

2010-09-16 16:29:15

sql server表

2010-09-25 10:41:34

SQL SERVER主

2010-09-13 16:19:47

Sql Server數(shù)

2010-10-19 13:05:31

Sql Server遠(yuǎn)

2010-09-28 11:07:37

SQL索引

2010-11-10 11:27:40

SQL Server重
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)