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.

 All Forums
 General SQL Server Forums
 Script Library
 Group by weekly data

Author  Topic 

kishoremcp
Starting Member

41 Posts

Posted - 2013-10-18 : 03:43:24
hi,
I have a column where dates are available.
Ex: where the date starts from 2010-02-26 09:53:45.397 and ends at
2013-09-30 04:00:02.907.

I want to have data for 26 weeks only. How do i get it.

The date column name is Period and another column is Metrics.

Is there is a possibility? If so how?

Thanks in advance....

Regards
Kishore

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-10-18 : 08:14:49
26 weeks from when? from today backwards? or from latest date backwards?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

kishoremcp
Starting Member

41 Posts

Posted - 2013-10-18 : 09:12:04
I need it from today to backwards..

quote:
Originally posted by visakh16

26 weeks from when? from today backwards? or from latest date backwards?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs




Regards
Kishore
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-10-18 : 09:27:36
[code]
select ...
from ...
where [date] >= DATEADD(wk,DATEDIFF(wk,0,GETDATE())-26,0)
AND [date] < DATEADD(dd,DATEDIFF(dd,0,GETDATE()),1)
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-10-18 : 09:29:52
also see

http://visakhm.blogspot.in/2012/12/different-ways-to-implement-date-range.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

kishoremcp
Starting Member

41 Posts

Posted - 2013-10-18 : 10:17:49
Thank you. I will try it and let you know the result.



quote:
Originally posted by visakh16

also see

http://visakhm.blogspot.in/2012/12/different-ways-to-implement-date-range.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs




Regards
Kishore
Go to Top of Page
   

- Advertisement -