Solved

T-SQL / How to display leading zeros

Posted on 2000-05-07
2
1,054 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

733 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