Author |
Topic |
cutiebo2t
Constraint Violating Yak Guru
256 Posts |
Posted - 2008-05-11 : 23:44:35
|
Is there a way I can filter dates for last week (May 4 - 10)? This mean that every Mondays, I'll be getting last week's date range. Thanks |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-11 : 23:56:13
|
DECLARE @PrevWeekStart datetime,@PrevWeekEnd datetimeSET @PrevWeekStart =@DATEADD(wk,-1,GETDATE()) - DATEPART(dw,GETDATE()) + 1SET @PrevWeekEnd =DATEADD(dd,6,@PrevWeekStart) |
|
|
cutiebo2t
Constraint Violating Yak Guru
256 Posts |
Posted - 2008-05-11 : 23:57:24
|
Thanks but can it be under the WHERE function? |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
cutiebo2t
Constraint Violating Yak Guru
256 Posts |
Posted - 2008-05-12 : 04:39:53
|
this one is different. Is there a way I can filter dates for last week (May 4 - 10)? This mean that every Mondays, I'll be getting last week's date range. Thanks |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-12 : 04:42:46
|
quote: Originally posted by cutiebo2t this one is different. Is there a way I can filter dates for last week (May 4 - 10)? This mean that every Mondays, I'll be getting last week's date range. Thanks
Just use the query provided earlier to get dates and use it in your where clauseWHERE DateColumn >@PrevWeekStart AND DateColumn <=@PrevWeekEnd |
|
|
cutiebo2t
Constraint Violating Yak Guru
256 Posts |
Posted - 2008-05-12 : 04:47:38
|
Here's my formula but it's computing next week's data.WHERE (SesDate < DATEADD(WEEK, DATEDIFF(WEEK, '18991231', GETDATE()), '19000107')) AND (SesDate >= DATEADD(WEEK, DATEDIFF(WEEK, '19000101', GETDATE()), '18991231')) |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-12 : 05:11:27
|
quote: Originally posted by cutiebo2t Here's my formula but it's computing next week's data.WHERE (SesDate < DATEADD(WEEK, DATEDIFF(WEEK, '18991231', GETDATE()), '19000107')) AND (SesDate >= DATEADD(WEEK, DATEDIFF(WEEK, '19000101', GETDATE()), '18991231'))
Did you try the query i posted? |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-05-12 : 05:11:37
|
And the week before is 7 days earlier.What could you possible change to get that result? E 12°55'05.25"N 56°04'39.16" |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
cutiebo2t
Constraint Violating Yak Guru
256 Posts |
Posted - 2008-05-12 : 05:13:18
|
not really sure how. Can you help me where to get that? I think I would learn the concept. |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-05-12 : 05:15:35
|
What about the six other occasions?You didn't learn then. What are the odds you will learn this time?What have changed since the other six occasions? E 12°55'05.25"N 56°04'39.16" |
|
|
cutiebo2t
Constraint Violating Yak Guru
256 Posts |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-05-12 : 05:28:39
|
Ok, here it is, step by step..1) What is the difference between one full week and two full weeks? E 12°55'05.25"N 56°04'39.16" |
|
|
cutiebo2t
Constraint Violating Yak Guru
256 Posts |
Posted - 2008-05-12 : 05:32:35
|
I know the difference but not sure with the formula. |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-05-12 : 05:33:34
|
Do you want a step by step explanation or not? E 12°55'05.25"N 56°04'39.16" |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-12 : 05:34:08
|
quote: Originally posted by cutiebo2t I know the difference but not sure with the formula.
Thats because you're concerned only with solving out your current problem rather than understanding the solution provided and concept behind. |
|
|
cutiebo2t
Constraint Violating Yak Guru
256 Posts |
Posted - 2008-05-12 : 05:36:37
|
It's okay I understand. I hope you understand that I'm new to this and I just know the basics. Anyway, thanks for all your help. I appreciate it. |
|
|
|