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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 group string

Author  Topic 

ilimax
Posting Yak Master

164 Posts

Posted - 2009-02-24 : 13:57:08
I have stored date-time as string in table in this format YYYYMMDDHHMM ... example200902252353

I want tome make query, something like this

SELECT COUNT(id) AS Counter, MIN(TimeOut) As TimeIn, SUBSTRING(TimeOut,8,2) AS [HRO] WHERE TimeIn > '200901010000'
GROUP BY [HRO]

So, I need to count visits by hour. I also need date of that grouping and week.



visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-25 : 10:33:30
something like

SELECT COUNT(id) AS Counter, MIN(TimeOut) As TimeIn,CONVERT(datetime,LEFT(TimeOut,8),112) AS date, SUBSTRING(TimeOut,9,2)*1 AS hours
WHERE TimeIn > '2009-01-01 00:00:00'
GROUP BY CONVERT(datetime,LEFT(TimeOut,8),112),SUBSTRING(TimeOut,9,2)*1
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-02-25 : 10:42:32
Add
datename(week,getdate())
to above since you want week as well.
Go to Top of Page
   

- Advertisement -