类型 DATE 不是定义的系统类型 [英] Type DATE is not a defined system type

查看:20
本文介绍了类型 DATE 不是定义的系统类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试试这个来消磨时间

   select CONVERT(char(10), [Reg Date1], 103) [Reg Date], Regs
    from (
          select cast(SetupDateTime as DATE) [Reg Date1]
               , COUNT(distinct ID) [Regs]
          from dbo.tbl_User
          where cast(SetupDateTime as DATE) 
                between cast((DATEADD (dd , -7 , GETDATE())) AS DATE) 
                    and cast((DATEADD (dd , -1 , GETDATE())) AS DATE)
          group by cast(SetupDateTime as DATE)
        ) a
    order by a.[Reg Date1]

但我收到此错误

消息 243,级别 16,状态 1,第 1 行
类型 DATE 不是定义的系统类型.

Msg 243, Level 16, State 1, Line 1
Type DATE is not a defined system type.

推荐答案

您使用的是 SQL Server 2005 或更早版本.SQL Server 2008 中引入了数据类型 date.尝试强制转换为 日期时间.

You are using SQL Server 2005 or earlier. Data type date was introduced in SQL Server 2008. Try to cast to datetime instead.

看看这个关于如何从日期时间中删除时间部分的问题.在 SQL 中删除日期时间的时间部分的最佳方法服务器

Have a look at this question on how to remove the time part from a datetime. Best approach to remove time part of datetime in SQL Server

这篇关于类型 DATE 不是定义的系统类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆