如何从sql server 2008的日期提取一年? [英] how to extract only the year from the date in sql server 2008?

查看:160
本文介绍了如何从sql server 2008的日期提取一年?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在sql server 2008中,如何从日期提取年份。
在DB中我有一个列的日期,从那里我需要提取一年。
是否有任何功能?

In sql server 2008, how to extract only the year from the date. In DB I have a column for date, from that I need to extract the year. Is there any function for that?

推荐答案

year(@date)
year(getdate())
year('20120101')

update table
set column = year(date_column)
whre ....

或者您需要在另一个表中

or if you need it in another table

 update t
   set column = year(t1.date_column)
     from table_source t1
     join table_target t on (join condition)
    where ....

这篇关于如何从sql server 2008的日期提取一年?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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