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 2000 Forums
 Transact-SQL (2000)
 Can't do month() + year()

Author  Topic 

rohcky
Starting Member

38 Posts

Posted - 2006-05-09 : 10:29:08
I apologize for making another post so soon, but I'm having trouble concatenating a string after using the month and year function. Is it even possible to do that?

SELECT MONTH(date) + '/' + YEAR(date) as DATE
FROM table

Result: Syntax error converting the varchar value '/' to a column of data type int

SELECT MONTH(date) + YEAR(date) as DATE
FROM table

Result:
------
DATE
------
2001
2001
2001
2002
2002
2003
etc...

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-05-09 : 10:53:17
This should do what you want:

select
right(convert(varchar(10),date,103),7)as DATE
from
(select date = getdate() ) a


Results:

DATE
-------
05/2006

(1 row(s) affected)



CODO ERGO SUM
Go to Top of Page

rohcky
Starting Member

38 Posts

Posted - 2006-05-09 : 11:12:47
Mr. MVJ,

You are a godsend. Thank you very much.

I noticed that the results are printed dd/mm/yyyy. Is there a way to have it printed mm/dd/yyyy?
Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-05-09 : 15:09:18
rohcky, check the Books Online (SQL Server Help) - Convert - Transact SQL
U will find how to get the various date formats
Also u can make use of the Front End side formatting.

Srinika
Go to Top of Page
   

- Advertisement -