Solved

SQL 2000 - Concatenate String on Set Command

Posted on 2012-04-12
2
273 Views
Last Modified: 2012-04-13
I'm trying to concatenate two stings together on the set command, but instead of concatenating it is adding the two strings together.

@ProcessDate = '4/2/2012'

declare @YearMonth varchar(6)
set @YearMonth = Year(@ProcessDate) + REPLICATE('0',LEN(Month(@ProcessDate))) + CONVERT(varchar(2),Month(@ProcessDate))

Instead of getting 201204 - Which is what I want I'm getting 2016

Thanks,
Mark
0
Comment
Question by:smithmrk
2 Comments
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 500 total points
ID: 37840126
set @YearMonth = CAST(Year(@ProcessDate) AS char(4)) + REPLICATE('0',LEN(Month(@ProcessDate))) + CONVERT(varchar(2),Month(@ProcessDate))
0
 

Author Closing Comment

by:smithmrk
ID: 37842777
Wonderful!!!!

Thanks,
Mark
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sql query help 7 98
sql calculate reminders 11 70
Delete from table 6 46
display data in text field from data base for updating 6 51
Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

863 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

25 Experts available now in Live!

Get 1:1 Help Now