Solved

SQL 2000 - Concatenate String on Set Command

Posted on 2012-04-12
2
278 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Change variables in SQL table 6 95
SQL Select - Finding chars in a column 2 67
Need help debbuging stored procedure 21 44
How can i use WITH CTE for checking exist value? 3 47
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 …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

821 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