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
Where can I find a Terrain Elevation Database of the United States?
password for isql
Flash player only works when logged in as admin
How to create repeating pages in Word
Flash & Google Bot
How to stop relaying on rcpt to level
Delegate ability to add computers to domain but not delete
Installing WMI Windows Installer Provider using SYSOCMGR.exe
how to open a port on cisco 1700
WINSTLE Error creating Office 07 msi ODSERV.exe not found