Type DATE is not a defined system type

2019-06-15 07:44发布

Trying this to cast time away

   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]

but I get this error

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

2条回答
该账号已被封号
2楼-- · 2019-06-15 08:07

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

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

查看更多
forever°为你锁心
3楼-- · 2019-06-15 08:09

If you are using Sybase ASE, what you need is datetime.

查看更多
登录 后发表回答