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 - 2009-08-03 : 06:22:52
|
| i have select count(id) from customers where signedupdate<getdate()-7How can I get to include the last 7 days but not counting saturday and sunday? |
|
|
rocknpop
Posting Yak Master
201 Posts |
Posted - 2009-08-03 : 06:33:56
|
| Check this: Select DATENAME(dw , getDate()) So your query becomes:And DATENAME(dw , getDate()) <> 'Saturday' And DATENAME(dw , getDate()) <> 'Sunday'Check this too, it talks about avoiding functions in where clause:http://www.mssqltips.com/tip.asp?tip=1236So maybe you could use a CTE.Edit:SELECT COUNT(ID) FROM(SELECT ID,signedupdate,CASE DATENAME(dw ,signedupdate) WHEN 'Sunday' THEN 0 WHEN 'Saturday' THEN 0 Else 1ENDAS dayName From customers Where signedupdate<getdate()-7) AS A WHERE dayName=1--------------------Rock n Roll with SQL |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2009-08-05 : 14:50:42
|
| rocknpop - yours doesn't work in the end what I did was the I check the current day of the week if it's sunday I do getdate()-8if 2 I do getdate()-93 - getdate()-94 getdate()-85 getdate()-76 getdate()-77 getdate()-7any reason that should not do it? |
 |
|
|
|
|
|