Microsoft
Software
Hardware
Network
Question : CAST(MONTH(DDate) AS VarChar(20)) need two digits not one.
I am using the following SQL to return the month number.
CAST(MONTH(DDate) AS VarChar(20)) as MonthNumber
The results are a single digit. For example, 2 instead of 02.
How can I put in a leading zero where needed and miss it out on months which are already two digits long?
Answer : CAST(MONTH(DDate) AS VarChar(20)) need two digits not one.
try
select
Case When Len(CAST(MONTH(DDate) AS VarChar(20))) = 1
then '0' + CAST(MONTH(DDate) AS VarChar(20))
Else CAST(MONTH(DDate) AS VarChar(20)) End
as MonthNumber
Random Solutions
Link External Data - Can a Link Specification be Updated?
Incorrect Syntax when running stored procedure
What is the Run-time error 2282?
Help !!! Strange archive problem in Outlook 2007
Exporting to excel and formatting the spreadsheet from VB
Need DumpCFG.exe for windows 2000 resource disk.....
Software Raid 5 Install Druid Issues w/Linux Fedora
Convert C-ISAM files either to Access or SQL
Export MS SQL Report to PDF with Tree Index/TOC and Page Navigation
Linux FTP Jail - Sortof