Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Concatenate Year and Month values

Author  Topic 

JCirocco
Constraint Violating Yak Guru

392 Posts

Posted - 2009-08-28 : 10:44:38
I am trying to take the transaction date for the last year and create a calculated value that concatenates the year, a "/" and the month# so that I can drop them into 12 buckets. the format needs to look like:
yyyy/mm

I have tried:
Char(DATEPART(year, Rn_Create_Date)) + '/' + Char(DATEPART(month, Rn_Create_Date))

but is returns NULL

Doing just DATEPART(year, Rn_Create_Date) does return the 2009



John

"The smoke monster is just the Others doing barbecue"

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-08-28 : 10:48:46
this?

select convert(varchar(7),Rn_Create_Date,111)
Go to Top of Page

JCirocco
Constraint Violating Yak Guru

392 Posts

Posted - 2009-08-28 : 10:56:02
vijayisonly,

Exactly!

I guess I need to read up on Convert and its arguments...

Thanks.


John

"The smoke monster is just the Others doing barbecue"
Go to Top of Page

JCirocco
Constraint Violating Yak Guru

392 Posts

Posted - 2009-08-28 : 10:58:42
What threw me was the varchar(7). I didn't know you could truncate the result. So simple...

John

"The smoke monster is just the Others doing barbecue"
Go to Top of Page

cat_jesus
Aged Yak Warrior

547 Posts

Posted - 2009-08-28 : 10:58:52
Yes, BOL has a really good writeup on convert. I'ts probably one of my most frequently referenced pages.



An infinite universe is the ultimate cartesian product.
Go to Top of Page
   

- Advertisement -