• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1112
  • Last Modified:

T-SQL / How to display leading zeros

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
ravl
Asked:
ravl
1 Solution
 
manchulaCommented:
Try this query:

SELECT STUFF('00', 2-len(MONTH(GETDATE()))+1, 2, MONTH(GETDATE()))
0
 
ravlAuthor Commented:
STUFF!! What a wonderful function name. Thank you, that works a treat.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now