用sql語句如何查找一個日期

sfanpu 2005-03-08 04:24:50
比如

name birt
--------------------
erick 1999/2/2
winc 1988/2/3
rebert 1999/2/2

如何用sql語句查找birt為“2/2“的資料呢?其中birt類型為datatime

我用下面的語句查了但是不對
select * from table1 where birt like '%2/2%'

謝謝!
...全文
133 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
子陌红尘 2005-03-08
  • 打赏
  • 举报
回复
select
*
from
table1
where
replace(convert(varchar(10),birt,111),'/0','/') like '%2/2'
sfanpu 2005-03-08
  • 打赏
  • 举报
回复
謝謝各位!
remote_peng 2005-03-08
  • 打赏
  • 举报
回复
select * from table where month(birt)=2 and day(birt)=2
LoveLwn 2005-03-08
  • 打赏
  • 举报
回复
select * from table1 where convert(char(5),birt,101)='2/2'

足够了
xluzhong 2005-03-08
  • 打赏
  • 举报
回复

create table kk(name varchar(10), birt datetime)
insert into kk
select 'erick' , '1999/2/2' union all
select 'winc' , '1988/2/3' union all
select 'rebert', '1999/2/2'
----------------------------實現語句-----------
select * from KK where convert(char(5),birt,101)='02/02'

DROP TABLE KK
xluzhong 2005-03-08
  • 打赏
  • 举报
回复
select * from table1 where convert(char(5),birt,101)='02/02'
Softlee81307 2005-03-08
  • 打赏
  • 举报
回复
create table kk(name varchar(10), birt datetime)
insert into kk
select 'erick' , '1999/2/2' union all
select 'winc' , '1988/2/3' union all
select 'rebert', '1999/2/2'
----------------------------實現語句-----------
select * from kk where cast(datepart(mm,birt) as varchar(2))+'/'+cast(datepart(dd,birt) as varchar(2)) ='2/2'
---------------結果------------------
erick 1999-02-02 00:00:00.000
rebert 1999-02-02 00:00:00.000
Softlee81307 2005-03-08
  • 打赏
  • 举报
回复
select * from kk where cast(datepart(mm,birt) as varchar(2))+'/'+cast(datepart(dd,birt) as varchar(2)) ='2/2'
Softlee81307 2005-03-08
  • 打赏
  • 举报
回复
create table kk(name varchar(10), birt datetime)
insert into kk
select 'erick' , '1999/2/2' union all
select 'winc' , '1988/2/3' union all
select 'rebert', '1999/2/2'


----------------------------
select * from kk where cast(datepart(mm,birt) as varchar(2))+'/'+cast(datepart(dd,birt) as varchar(2)) ='2/2'
xluzhong 2005-03-08
  • 打赏
  • 举报
回复
select * from table1 where convert(char(5),birt,101)='2/2'

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧