Solved

SQL 2000 - Concatenate String on Set Command

Posted on 2012-04-12
2
270 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:
ScottPletcher 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
In this article I will describe the Copy Database Wizard 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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

757 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

20 Experts available now in Live!

Get 1:1 Help Now