Solved

concat year from datetime

Posted on 2014-12-08
2
81 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:ScottPletcher
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now