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
 New to SQL Server Programming
 Last Week

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 datetime


SET @PrevWeekStart =@DATEADD(wk,-1,GETDATE()) - DATEPART(dw,GETDATE()) + 1
SET @PrevWeekEnd =DATEADD(dd,6,@PrevWeekStart)
Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 2008-05-11 : 23:57:24
Thanks but can it be under the WHERE function?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-05-12 : 02:12:23
Have all of the previous answers learnt you nothing?

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=102596
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=102444
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=102203
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=102008
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=101993

All the links above is the same question as you now ask again.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

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
Go to Top of Page

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 clause

WHERE DateColumn >@PrevWeekStart AND DateColumn <=@PrevWeekEnd
Go to Top of Page

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'))
Go to Top of Page

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?
Go to Top of Page

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"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-05-12 : 05:13:00
quote:
Originally posted by cutiebo2t

this one is different.
How is this different from this one?
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=102203



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

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.
Go to Top of Page

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"
Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 2008-05-12 : 05:25:10
If you can guide me step by step, I would really appreciate it. If you can't, I would understand. It's different to this http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=102203, because it computes the 2 weeks. Just need the current week.
Go to Top of Page

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"
Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 2008-05-12 : 05:32:35
I know the difference but not sure with the formula.
Go to Top of Page

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"
Go to Top of Page

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.
Go to Top of Page

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.
Go to Top of Page
   

- Advertisement -