[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1082
  • 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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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