SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Save Month & Year
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Steve2106
Posting Yak Master

United Kingdom
149 Posts

Posted - 08/16/2012 :  16:39:13  Show Profile  Reply with Quote
Hi There,

I need to update a table field with the Month & Year of a field with a date in it.

I have tried this:
UPDATE Rental
SET MonYear = MONTH(RentalStartDate) + YEAR(RentalStartDate)

But where the month is 08 and the year is 2012 I get a result of 2020 (08 + 2012 = 2020) instead of 082012 as a concate of the two

Any help would be appreciated.

Best regards,




Steve

visakh16
Very Important crosS Applying yaK Herder

India
47023 Posts

Posted - 08/16/2012 :  16:49:13  Show Profile  Reply with Quote

UPDATE Rental
SET MonYear = CAST(MONTH(RentalStartDate) AS varchar(2)) + CAST( YEAR(RentalStartDate) AS varchar(4))



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Steve2106
Posting Yak Master

United Kingdom
149 Posts

Posted - 08/17/2012 :  04:18:16  Show Profile  Reply with Quote
Hi Visakh,

Thaks for your reply.

That's perfect, thank you.

Best Regards,



Steve
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47023 Posts

Posted - 08/17/2012 :  10:22:56  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000