?
Solved

T-SQL / How to display leading zeros

Posted on 2000-05-07
2
Medium Priority
?
1,069 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 200 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

800 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