从日期时间偏移列中获取YEAR [英] Get YEAR out of datetimeoffset column

查看:62
本文介绍了从日期时间偏移列中获取YEAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。



我在获取datetimeoffset字段的年份时遇到问题。

我想分组一堆每年的记录,但每当我试图获得一年的时间我从SQL服务器收到错误。



我的代码如下



选择年份[过帐日期]

来自[客户。 Ledger Entry]



如果我删除YEAR它工作正常,我得到11.000行日期戳,如下格式:

2013-04 -29 00:00:00.0000000 +00:00



为什么这对我不起作用?

Hello everyone

I have a problem with getting the year our of a datetimeoffset field.
I would like to Group a bunch of records by year but whenever i try to get the year out i recieve en error from the SQL server.

My code is as follows

Select YEAR[Posting Date]
From [Cust. Ledger Entry]

If i remove the YEAR it Works fine and i get 11.000 rows with date stamp like this format:
2013-04-29 00:00:00.0000000 +00:00

Why is this not working for me??

推荐答案

在SQL括号中用于包含对象(列,表)名称,其中包含关键字以使解释更容易...

然而 [ ^ ]是一个函数,应该与括号一起使用...

In SQL brackets used to enclose object (column, table) names that contains keywords to make interpretation easier...
However YEAR[^] is a function and should be used with parentheses...
Select YEAR([Posting Date])
From [Cust. Ledger Entry]


这篇关于从日期时间偏移列中获取YEAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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