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 |
|
osupratt
Posting Yak Master
238 Posts |
Posted - 2008-05-23 : 10:03:24
|
| I'm trying to find a simple way to see if a date in a week. I would like to try something like this, but haven't gotten it to work yet:case when snapshot_date in (datepart(week,getdate())) then 'yes' else 'no' end as week1,case when snapshot_date in (datepart(week,getdate())-1) then 'yes' else 'no' end as week2What am I doing wrong and how would I correctly go about this? |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-05-23 : 10:05:28
|
Date is specific date, right?DATEPART(WEEK, ... ) returns a number, right? E 12°55'05.25"N 56°04'39.16" |
 |
|
|
osupratt
Posting Yak Master
238 Posts |
Posted - 2008-05-23 : 10:05:38
|
| Never mind. I figured it out. Thanks. |
 |
|
|
osupratt
Posting Yak Master
238 Posts |
Posted - 2008-05-23 : 10:06:15
|
| case when datepart(week,snapshot_date) =(datepart(week,getdate())) then 'yes' else 'no' end as week1,case when datepart(week,snapshot_date) = (datepart(week,getdate())-1) then 'yes' else 'no' end as week2 |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-05-23 : 10:08:53
|
If you are going to ruin the index on snapshot_date, this is less to type.case when datediff(week, snapshot_date, getdate()) = 0 then 'yes' else 'no' end as week1 E 12°55'05.25"N 56°04'39.16" |
 |
|
|
osupratt
Posting Yak Master
238 Posts |
Posted - 2008-05-23 : 10:28:37
|
| Could you please explain the 'ruin index' on snapshot_date? |
 |
|
|
|
|
|
|
|