Friday, March 23, 2012

Month data

HI,
I have a datetime column and it has 2 years of data. How
do I select the data that is only belong to the current
month (Whether it is the beginning/middle/end of the
month) '
Thanks for any help.There's a couple of different options for doing this, but this one should do
the trick:
select <insert your column list here>
from table1
where month(YourDate) = month(current_timestamp)
and year(YourDate) = year(current_timestamp)
--Brian
(Please reply to the newsgroups only.)
"Chris" <anonymous@.discussions.microsoft.com> wrote in message
news:5e7601c40092$e4c66910$a101280a@.phx.gbl...
> HI,
> I have a datetime column and it has 2 years of data. How
> do I select the data that is only belong to the current
> month (Whether it is the beginning/middle/end of the
> month) '
> Thanks for any help.|||Thanks.......
I found it
Select * from mytable
where column >= cast(month(getdate()) as varchar(2))
+ '/01/' + cast(year(getdate()) as varchar(4))

>--Original Message--
>There's a couple of different options for doing this, but
this one should do
>the trick:
>select <insert your column list here>
> from table1
> where month(YourDate) = month(current_timestamp)
> and year(YourDate) = year(current_timestamp)
>--
>--Brian
>(Please reply to the newsgroups only.)
>
>"Chris" <anonymous@.discussions.microsoft.com> wrote in
message
>news:5e7601c40092$e4c66910$a101280a@.phx.gbl...
>
>.
>sql

No comments:

Post a Comment