Solved

T-SQL / How to display leading zeros

Posted on 2000-05-07
2
1,041 Views
Last Modified: 2012-08-14
SELECT MONTH(GETDATE()) today displays the result 5. How can I display or store the result as the character string '05' without using concatention? EG. in Access I would say Format(month(date(),"00"). How do I do this in T-SQL?
0
Comment
Question by:ravl
2 Comments
 
LVL 1

Accepted Solution

by:
manchula earned 50 total points
ID: 2787022
Try this query:

SELECT STUFF('00', 2-len(MONTH(GETDATE()))+1, 2, MONTH(GETDATE()))
0
 
LVL 1

Author Comment

by:ravl
ID: 2787055
STUFF!! What a wonderful function name. Thank you, that works a treat.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

932 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now