| Author |
Topic |
|
dimoss
Yak Posting Veteran
52 Posts |
Posted - 2007-04-09 : 03:35:54
|
| Hi,I am new to SQL and I have a problem to deal with dates.I have a field called LogDate (smalldatetime) and default value getdate(). The date is added immediately when a visitor visits a page of my site.The problem is that I cannot retrieve the no of the visitors for today using getdate(). I use the following query but I am sure that something missing.SELECT Count(*) As DailyVisitorsFROM statsWHERE LogDate = CONVERT(varchar(10), GETDATE(), 103)Please helpDeniswww.tabletennis.gr |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-04-09 : 03:37:42
|
[code]SELECT Count(*) As DailyVisitorsFROM statsWHERE LogDate >= dateadd(day, datediff(day, 0, getdate()), 0)and LogDate < dateadd(day, datediff(day, 0, getdate()), 1)[/code] KH |
 |
|
|
dimoss
Yak Posting Veteran
52 Posts |
Posted - 2007-04-09 : 03:42:05
|
| Wow! Fast reply!!Thank you so much!!www.tabletennis.gr |
 |
|
|
dimoss
Yak Posting Veteran
52 Posts |
Posted - 2007-04-09 : 03:49:35
|
| Something else..If I want to GROUP BY the ip address and get the unique visitors I use the following according to what you wrote BUT for some reason it returns all the records.SELECT COUNT(*) AS DayUniqueFROM (SELECT LogRemote_Addr FROM stats GROUP BY LogRemote_Addr, LogDate HAVING LogDate >= dateadd(day, datediff(day, 0, getdate()), 0) AND LogDate < dateadd(day, datediff(day, 0, getdate()), 1)) DERIVEDTBLAny ideas?Thanks.www.tabletennis.gr |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-04-09 : 03:52:36
|
because you are grouping by LogDateSELECT COUNT(*) AS DayUniqueFROM ( SELECT LogRemote_Addr FROM stats WHERE LogDate >= dateadd(day, datediff(day, 0, getdate()), 0) AND LogDate < dateadd(day, datediff(day, 0, getdate()), 1) GROUP BY LogRemote_Addr) DERIVEDTBL KH |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-04-09 : 03:55:06
|
You can also do this SELECT count(distinct LogRemote_Addr) FROM stats WHERE LogDate >= dateadd(day, datediff(day, 0, getdate()), 0) AND LogDate < dateadd(day, datediff(day, 0, getdate()), 1) KH |
 |
|
|
dimoss
Yak Posting Veteran
52 Posts |
Posted - 2007-04-09 : 04:06:59
|
| Yes!!Much more simpler using Distinct!I have a lot to learn...:-)Thanks!www.tabletennis.gr |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-04-11 : 08:45:10
|
quote: Originally posted by khtan don't forget this one from the Sainthttp://www.sqlteam.com/item.asp?ItemID=26922 KH
OP's next question would be "Who is Saint?" MadhivananFailing to plan is Planning to fail |
 |
|
|
|