Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2008-04-06 : 12:35:57
|
| i'm doing cast(month(dateofapplication) as varchar) but for this month it returns 4how can i get it to return 04 for all months of 1 character?i'm doing this within my select statement |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-04-06 : 12:43:31
|
| case when month(dateofapplication)<10 then '0' + cast(month(dateofapplication) as varchar) else cast(month(dateofapplication) as varchar)end |
 |
|
|
singularity
Posting Yak Master
153 Posts |
Posted - 2008-04-06 : 12:43:38
|
| case when month(dateofapplication) < 10 then '0' + cast(month(dateofapplication) as varchar) else cast(month(dateofapplication) as varchar) end |
 |
|
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2008-04-06 : 13:20:13
|
| thanks :) |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-04-06 : 13:25:58
|
CONVERT(CHAR(2), SomeDateTimeCol, 101) E 12°55'05.25"N 56°04'39.16" |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-04-08 : 03:22:53
|
quote: Originally posted by visakh16 case when month(dateofapplication)<10 then '0' + cast(month(dateofapplication) as varchar) else cast(month(dateofapplication) as varchar)end
1 You can simply do it right('0'+cast(month(dateofapplication) as varchar(2)),2)2 Beware of not specifying the column size for character datatype during convertions http://sqlblogcasts.com/blogs/madhivanan/archive/2007/12/04/column-length-and-data-length.aspxMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|