I have a stored procedure that returns YYYYMMDD formatted string.
I'm looking for the right way to create a string of MM and DD if the string supplied has only 1 character.
For example:
If day provided is 1, it needs to be changed to 01 and the same for the month.
declare @day as int
declare @month as int
select @day = 1
select @month = 9
Formatting code
select @day // gives 01
select @month // gives 09
I do not want to use if
logic here to check the length. Is that possible to use some kind of Formatting
functionality to achieve the same result?
I have found something like:
select right('0' + cast(@day as varchar(2)),2)
Would that be the correct solution?