Solved

concat year from datetime

Posted on 2014-12-08
2
84 Views
Last Modified: 2014-12-30
hI,
i HAVE UPDATE_DATE AS datetime,
i want to concat the year from that date

doing

select year(UPDATE_DATE) from x  not liking it
0
Comment
Question by:sam2929
2 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points
ID: 40487314
Define 'not liking it', preferably with whatever error message is returned when the above is executed.

The syntax select year(datetime_column_name) from table_name is correct, as the below code returns '2014' on my SQL 2008 box.
SELECT YEAR(GETDATE())

Open in new window

0
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 40487405
If you're trying to concatenate it, be sure to cast it to varchar as well:

select cast(year(UPDATE_DATE) as varchar(4)) + ...
from x
...
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Designing and Implementing a Data Warehouse 3 37
sql help 8 55
SQL Server - executing an agent job from a stored proc 2 19
export sql results to csv 6 36
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question