SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Script Library
 Group by weekly data
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kishoremcp
Starting Member

India
39 Posts

Posted - 10/18/2013 :  03:43:24  Show Profile  Reply with Quote
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

India
52317 Posts

Posted - 10/18/2013 :  08:14:49  Show Profile  Reply with Quote
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

India
39 Posts

Posted - 10/18/2013 :  09:12:04  Show Profile  Reply with Quote
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

India
52317 Posts

Posted - 10/18/2013 :  09:27:36  Show Profile  Reply with Quote

select ...
from ...
where [date] >= DATEADD(wk,DATEDIFF(wk,0,GETDATE())-26,0)
AND [date] < DATEADD(dd,DATEDIFF(dd,0,GETDATE()),1)


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

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 10/18/2013 :  09:29:52  Show Profile  Reply with Quote
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

India
39 Posts

Posted - 10/18/2013 :  10:17:49  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000