新手请教:SQLserver中有一datetime字段selldate不知用什么函数能取出他的时间,convert(varchar(10),selldate,102)怎么什么记录也查不到??

ssd 2001-12-17 04:22:24
select * from table1 where convert(varchar(10),selldate,102)='2001-12-12'
怎么什么记录也查不到
...全文
146 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
netcar 2001-12-17
  • 打赏
  • 举报
回复
将操作系统的短日期格式设置为yyyy-M-d或者yyyy-MM-dd
蓝天 2001-12-17
  • 打赏
  • 举报
回复
select * from table where year(selldate)=2001 and month(selldate)=12 and day(selldate)=12
Rayking 2001-12-17
  • 打赏
  • 举报
回复
select selldate-cast(selldate-0.5 as int) as 你要的时间 from table1
三杯倒 2001-12-17
  • 打赏
  • 举报
回复
应该把'2001-12-12',转换成date型比较

select * from table1 where convert(varchar(10),selldate,102)='2001-12-12'
如果selldate为索引,此索引将不起任何意义
kanghl 2001-12-17
  • 打赏
  • 举报
回复
select * from table1 where convert(char(10),selldate,102)='2001.12.12'
select * from table1 where convert(char(10),selldate,111)='2001/12/12'

34,590

社区成员

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

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