Solved

SQL 2000 - Concatenate String on Set Command

Posted on 2012-04-12
2
285 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

726 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