【问题标题】:Searching for records using Date >=使用 Date >= 搜索记录
【发布时间】:2021-08-26 14:23:02
【问题描述】:

我有一个小表,想搜索 >= 到 2021 年 6 月 1 日的记录。我做了以下操作

Select ApplyDate from zPermitsToCAMA where ApplyDate >=2019-01-01

我收到 Msg 206,Level 16,State 2,Line 1 操作数类型冲突:日期与 int 不兼容

【问题讨论】:

  • 请分享更多细节。您使用的是哪种“桌子”?您尝试过什么来解决给定的问题?
  • 你需要使用'2019-01-01'
  • 或者,如果您实际上是指 2021 年 6 月 1 日,请使用 where ApplyDate >= '2021-06-01'
  • 如果日期文字周围没有所需的引号,则计算数值表达式。 (2019 年减 1 减 1 等于 2017 年)。整数转换为日期时间值以进行比较 (1905-07-11 00:00:00.000)..
  • 感谢 Peter B. 我所缺少的

标签: sql-server date tsql


【解决方案1】:
Select ApplyDate from zPermitsToCAMA where ApplyDate >= 2019-01-01

评估为

Select ApplyDate from zPermitsToCAMA where ApplyDate >= 2017

(以2019开头并减去1两次)

你想引用日期

Select ApplyDate from zPermitsToCAMA where ApplyDate >= '2019-01-01'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-20
    • 1970-01-01
    • 2017-05-12
    • 1970-01-01
    • 2015-04-15
    • 2011-05-04
    • 1970-01-01
    相关资源
    最近更新 更多