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 |
|
rcr69er
Constraint Violating Yak Guru
327 Posts |
Posted - 2008-11-27 : 09:44:34
|
| Hi GuysI really hope you can help me with this. I am using the following query:SELECT DATENAME(dw,r.DateEntered) AS 'DayOfWeek' ,COUNT(ReceiptId) AS 'Orders'FROM Receipt AS r WITH (NOLOCK)WHERE DATEDIFF(wk,r.DateEntered,GETDATE()) = 0AND DATEDIFF(yy,r.DateEntered,GETDATE()) = 0GROUP BY DATENAME(dw,r.DateEntered)ORDER BYDATENAME(dw,r.DateEntered) ASCThis query is meant to produce the number of products sold this week.I get the following results:Monday 14932Sunday 13511Thursday 8548Tuesday 20860Wednesday 21199The first thing is that the first day of the week for here (UK) is Monday, so there shouldn’t be no Sunday figures as of yet because today is Thursday.Secondly how come the day names are not being shown in order?Thanking you in advance!!! |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-11-27 : 09:47:56
|
[code]SELECT DATENAME(dw, r.DateEntered) AS [DayOfWeek], COUNT(ReceiptId) AS OrdersFROM Receipt AS r WITH (NOLOCK)WHERE DATEDIFF(wk, r.DateEntered, GETDATE()) = 0GROUP BY DATENAME(dw, r.DateEntered), DATEPART(dw, r.DateEntered)ORDER BY DATEPART(dw, r.DateEntered)[/code] E 12°55'05.63"N 56°04'39.26" |
 |
|
|
rcr69er
Constraint Violating Yak Guru
327 Posts |
Posted - 2008-11-27 : 09:59:30
|
| Hey PesoThanks for that, but is there anyway of making Monday the first day?Thanks |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-11-27 : 10:07:37
|
[code]ORDER BY (DATEPART(dw, r.DateEntered) + 7) % 7][/code] E 12°55'05.63"N 56°04'39.26" |
 |
|
|
rcr69er
Constraint Violating Yak Guru
327 Posts |
Posted - 2008-11-27 : 10:14:13
|
| Thanks Peso |
 |
|
|
|
|
|
|
|