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.
| Author |
Topic |
|
learzbu
Starting Member
27 Posts |
Posted - 2011-11-17 : 12:04:05
|
| Hi,I wanted to know if there is a way to declare a non definite date range for running a query. What I want to do is run it for the previous week, so no matter what day I run the query on it will always run for the previous sunday to sunday period.Is there anything like this possible? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-17 : 12:08:07
|
yep. its possibleSELECT DATEADD(dd,DATEDIFF(dd,0,GETDATE())/7 * 7,0)-8 AS Start,DATEADD(dd,DATEDIFF(dd,0,GETDATE())/7 * 7,0)-1 AS end ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
learzbu
Starting Member
27 Posts |
Posted - 2011-11-17 : 13:36:32
|
| Thanks Again!! |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2011-11-17 : 13:43:52
|
Doesn't like endSELECT DATEADD(dd,DATEDIFF(dd,0,GETDATE())/7 * 7,0)-8 AS [Start],DATEADD(dd,DATEDIFF(dd,0,GETDATE())/7 * 7,0)-1 AS [end]SELECT DATEADD(dd,DATEDIFF(dd,0,GETDATE()+1)/7 * 7,0)-8 AS [Start],DATEADD(dd,DATEDIFF(dd,0,GETDATE()+1)/7 * 7,0)-1 AS [end] Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxWant to help yourself?http://msdn.microsoft.com/en-us/library/ms130214.aspxhttp://weblogs.sqlteam.com/brettk/http://brettkaiser.blogspot.com/ |
 |
|
|
learzbu
Starting Member
27 Posts |
Posted - 2011-11-17 : 14:44:35
|
| Ya i just took out end and replaced with finish |
 |
|
|
|
|
|
|
|