Hi Everyone:
I have a datetime column (col7) where the output is in the format mm/yyyy.
When I execute the following sql statement, I do get the result set as 8/200
5
or 10/2004. In all double-digit month numbers I do get the right output.
However, in case of single-digit month numbers I need the output as 08/2005
and not simply 8/2005. I would appreciate if someone can help me in this
direction.
****************************************
select (cast((datepart(month ,col7))as varchar(3))+'/'+ cast((datepart(year,
col7))as varchar(4)))as col7
FROM tablea
***************************
Thanks
Sujoy Paulright( '0' + cast( datepart(month, col7) as varchar(2)) , 2 )
"sujoyp" <sujoyp@.discussions.microsoft.com> wrote in message
news:3A4AAB69-8FE4-4F88-8BFF-30BD1C386CED@.microsoft.com...
> Hi Everyone:
> I have a datetime column (col7) where the output is in the format mm/yyyy.
> When I execute the following sql statement, I do get the result set as
8/2005
> or 10/2004. In all double-digit month numbers I do get the right output.
> However, in case of single-digit month numbers I need the output as
08/2005
> and not simply 8/2005. I would appreciate if someone can help me in this
> direction.
> ****************************************
> select (cast((datepart(month ,col7))as varchar(3))+'/'+
cast((datepart(year,
> col7))as varchar(4)))as col7
> FROM tablea
> ***************************
> Thanks
> Sujoy Paul
>|||research "case". if your month is less than 10 then you'll have just 1
diget.
> Hi Everyone:
> I have a datetime column (col7) where the output is in the format mm/yyyy.
> When I execute the following sql statement, I do get the result set as
> 8/2005 or 10/2004. In all double-digit month numbers I do get the right
> output. However, in case of single-digit month numbers I need the output
> as 08/2005 and not simply 8/2005. I would appreciate if someone can help
> me in this direction.
> ****************************************
> select (cast((datepart(month ,col7))as varchar(3))+'/'+
> cast((datepart(year, col7))as varchar(4)))as col7
> FROM tablea
> ***************************
> Thanks
> Sujoy Paul
new|||Thanks. It worked.
Sujoy
"Rebecca York" wrote:
> right( '0' + cast( datepart(month, col7) as varchar(2)) , 2 )
>
> "sujoyp" <sujoyp@.discussions.microsoft.com> wrote in message
> news:3A4AAB69-8FE4-4F88-8BFF-30BD1C386CED@.microsoft.com...
> 8/2005
> 08/2005
> cast((datepart(year,
>
>|||here's the year part too.
select right(convert(varchar(10), getdate(), 103), 7)
> right( '0' + cast( datepart(month, col7) as varchar(2)) , 2 )
>
> "sujoyp" <sujoyp@.discussions.microsoft.com> wrote in message
> news:3A4AAB69-8FE4-4F88-8BFF-30BD1C386CED@.microsoft.com...
> 8/2005
> 08/2005
> cast((datepart(year,
new
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment