请教 在 sql2000中, 日期'2009-06-01' 和 '2009-6-1' 相同吗?

dssw 2009-06-18 08:46:27
请教 在 sql2000中, 日期'2009-06-01' 和 '2009-6-1' 相同吗?

select 1 from sysfiles where '2009-06-01' = '2009-06-01'

请高人指点.
...全文
36 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
ai_li7758521 2009-06-18
  • 打赏
  • 举报
回复
日期类型相等,字符串不等。
dssw 2009-06-18
  • 打赏
  • 举报
回复
晓得了,
我怎么没有办法给分?
奇怪.
youzhj 2009-06-18
  • 打赏
  • 举报
回复
如果是字符串,那肯定不成立了。可以转换为小日期型。
nalnait 2009-06-18
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 JonasFeng 的回复:]
SQL code
select 1 from sysfiles where '2009-06-01' = '2009-6-1'


这肯定是不成立的。
因为是两个字符串。
但是作为日期他们是等的。

也就是

SQL code
select 1 from sysfiles where cast('2009-06-01' as smalldatetime) = cast('2009-6-1' as smalldatetime

)

这是OK
[/Quote].
SQL77 2009-06-18
  • 打赏
  • 举报
回复
select 1 from sysfiles where '2009-06-01' = '2009-6-1' 显然不正确,因为是字符串比较
select 1 from sysfiles where '2009-06-01' = '2009-06-01' 正确!!
JonasFeng 2009-06-18
  • 打赏
  • 举报
回复
 
select 1 from sysfiles where '2009-06-01' = '2009-6-1'

这肯定是不成立的。
因为是两个字符串。
但是作为日期他们是等的。

也就是

select 1 from sysfiles where cast('2009-06-01' as smalldatetime) = cast('2009-6-1' as smalldatetime
)

这是OK
--小F-- 2009-06-18
  • 打赏
  • 举报
回复
字符型的还是datetime的??

34,590

社区成员

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

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