Display date and Desc as varchar field

I'm in SQL Server and I want to update a varchar field with today's year and a desc.  Ex:
2012 Training
I've tried DATEPART(yy, { fn NOW() }) & ' Training'
but I get the error...
Conversion failed when converting the varchar value ' Training' to data type int.
How do I do this?
BobRosasAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Jim HornConnect With a Mentor Microsoft SQL Server Developer, Architect, and AuthorCommented:
SELECT CAST(YEAR(GETDATE()) as char(4)) + ' Training'
0
 
BobRosasAuthor Commented:
Thank you for your quick response!  It worked like a charm!
0
 
BobRosasAuthor Commented:
Excellent!
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Couple of things SQL-specific:
(1)  YEAR returns an integer, so to concatenate it with a string you have to CAST it as a string.
      So does DATEPART, which is why you received the error.
(2)  SQL uses plus marks ( + ) for string concatenation.
(3)  Did you want two-digit years (yy) or four (2012)?
0
 
BobRosasAuthor Commented:
The four digit year was just what I needed.
Thank you so much for the explanation as well.  I really appreciate it.
0
All Courses

From novice to tech pro — start learning today.