Jim Horn
asked on
Generating a leading zero in DatePart(mm, a_date)
Hi all
SELECT CAST(DATEPART(yyyy, '03/04/2004') as char(4)) + CAST(DATEPART(mm, '03/04/2004') as char(2))
returns 20043
I am trying to edit this to return 200403, and it's not abundantly clear how to pull this off.
Thanks.
-Jim
SELECT CAST(DATEPART(yyyy, '03/04/2004') as char(4)) + CAST(DATEPART(mm, '03/04/2004') as char(2))
returns 20043
I am trying to edit this to return 200403, and it's not abundantly clear how to pull this off.
Thanks.
-Jim
SELECT CAST(DATEPART(yyyy, '03/04/2004') as char(4)) + RIGHT('00'+CAST(DATEPART(m m, '03/04/2004') as char(2)),2)
ASKER
aneeshattingal - No love. Still showed 20043 when run in SQL2K Query Analyzer. -Jim
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
need to use varchar(2) instead of char(2)
ASKER
That worked. Thank you. -Jim