Solved

concat year from datetime

Posted on 2014-12-08
2
92 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 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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

688 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