?
Solved

concat year from datetime

Posted on 2014-12-08
2
Medium Priority
?
93 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 66

Accepted Solution

by:
Jim Horn earned 2000 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
In this article I will describe the Detach & Attach 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.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

800 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