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 |
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2008-10-20 : 03:32:06
|
| i have a table called registrantsidmydate (datetime field)namehow can i get 1. a count of all registrants where mydate is from last week - meaning last monday morning though sunday night2. a count of all this week - from monday morning to next monday morning (so if today is monday it will just show today but if today was friday it would show count of monday to friday) |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-20 : 04:12:10
|
| 1.select count(*) from registrants where mydate > dateadd(wk,datediff(wk,0,getdate())-1,0) and mydate <dateadd(wk,datediff(wk,0,getdate()),0)2.select count(*) from registrants where mydate > dateadd(wk,datediff(wk,0,getdate()),0) and mydate <dateadd(wk,datediff(wk,0,getdate())+1,0) |
 |
|
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2008-10-20 : 04:17:20
|
| thanks but one questionselect count(*) from appeals where mydatetime > dateadd(wk,datediff(wk,0,getdate())-1,0) and mydatetime <dateadd(wk,datediff(wk,0,getdate()),0)your doing -1 - does that mean tommorow this query would show this week?or even on friday it would still show last weeks count? (meaning whatever this shows me today it should also show me tomorrow?) is this correct |
 |
|
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2008-10-20 : 04:18:02
|
| nevermind i see your subtracting a week - this i what i needed - thanks |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-20 : 04:22:14
|
quote: Originally posted by esthera nevermind i see your subtracting a week - this i what i needed - thanks
cheers . what i'm doing with -1 is looking from last week beginning to this week beginning which is what you want. |
 |
|
|
|
|
|
|
|