Hi all,
I am writing a query that is doing a yearly breakdown.
I've been looking at the SQL date funcitons, but am a little confused
as to how best accomplish this.
Basically I want the query to get info from the 1-Jan this year, to
the 31-Dec this year.
If the SQL query is run in two years time, it needs to automatically
get the date range for that particular year.
(ie. I can't hardcode the year in the sql statement)
I've been messing around with getdate()... I can get the year
component of getdate... but I'm not sure how to then use that in my
query to do something like
where dateadded >= '01-Jan-'+year(getdate())
(I know the above it wrong but it shows what im trying to achieve..)
Any info would be very helpful
Thanks!!!
Hello,
Use CONVERT Function. see the below sample.
where dateadded >= '01-Jan-'+convert(char,year(getdate())) and dateadded
<='31-Dec-'+convert(char,year(getdate()))
Thanks
Hari
"David Conte" <davconts@.gmail.com> wrote in message
news:1170642986.078542.244700@.a75g2000cwd.googlegr oups.com...
> Hi all,
> I am writing a query that is doing a yearly breakdown.
> I've been looking at the SQL date funcitons, but am a little confused
> as to how best accomplish this.
> Basically I want the query to get info from the 1-Jan this year, to
> the 31-Dec this year.
> If the SQL query is run in two years time, it needs to automatically
> get the date range for that particular year.
> (ie. I can't hardcode the year in the sql statement)
> I've been messing around with getdate()... I can get the year
> component of getdate... but I'm not sure how to then use that in my
> query to do something like
> where dateadded >= '01-Jan-'+year(getdate())
> (I know the above it wrong but it shows what im trying to achieve..)
> Any info would be very helpful
> Thanks!!!
>
|||On Feb 5, 2:11 pm, "Hari Prasad" <hari_prasa...@.hotmail.com> wrote:[vbcol=seagreen]
> Hello,
> Use CONVERT Function. see the below sample.
> where dateadded >= '01-Jan-'+convert(char,year(getdate())) and dateadded
> <='31-Dec-'+convert(char,year(getdate()))
> Thanks
> Hari
> "David Conte" <davco...@.gmail.com> wrote in message
> news:1170642986.078542.244700@.a75g2000cwd.googlegr oups.com...
>
>
>
>
ahh excellent - thought I was missing a step! :D
I'll give it a try.
Thanks very much for the prompt reply Hari!
No comments:
Post a Comment