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
illegal operation when closing excel files
Microsoft Access Form Header Text Box - prevent from selecting
Print sideways to a plotter
No NDR
The advanced page cannot be opened because of following error: The server is not operational
Need semi-simple batch script will save me a ton of time and help a lot
Adsense Ads I don't want showing up on my site
IIS 6 need to run in x86 (32 bit mode) but on a Windows 2003 x64 server
User profile redirect
MYSQL is limiting the number of table rows to 32,767