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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help with datepart

Author  Topic 

Adreanne
Starting Member

9 Posts

Posted - 2007-05-03 : 09:13:12
I would like to take the following code and display the data / count by month. I want to see how many people are logging in by month.. I tried using the datepart but I keep getting an aggrefate comannd error can anyone help modify this query

SELECT DISTINCT Count(login.login_time) AS CountOflogin_time
FROM login
WHERE login.login_time>=#10/1/2005#;

Thanks,

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-05-03 : 09:15:44
SELECT DATEADD(MONTH, DATEDIFF(MONTH, 0, Login_Time), 0) AS Month, COUNT(*) AS Cnt
FROM Login
WHERE Login_Time >= '20051001'
GROUP BY DATEADD(MONTH, DATEDIFF(MONTH, 0, Login_Time), 0)
ORDER BY 1


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-05-03 : 09:19:40
SELECT YEAR(Login_Time) AS Year, MONTH(Login_Time) AS Month, COUNT(*) AS Cnt
FROM Login
WHERE Login_Time >=#10/1/2005#
GROUP BY YEAR(Login_Time), MONTH(Login_Time)
--ORDER BY YEAR(Login_Time), MONTH(Login_Time)


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

Adreanne
Starting Member

9 Posts

Posted - 2007-05-03 : 09:22:04
Thanks a bunch for the code. However, I put the code in and I got an error it says:

Circular reference caused by Alias Month in query definition's Select List
Go to Top of Page

Adreanne
Starting Member

9 Posts

Posted - 2007-05-03 : 09:24:03
IT WORKED YOU ARE A LIFE SAVER PESO!
Go to Top of Page
   

- Advertisement -