Greetings!
If I have two columns, the first is a SQL function to provide the time from hour to hour:
declare @HStr int
set @HStr = convert(varchar,datepart(hour,@startTime))+'
- '+convert(varchar,datepart(hour,@startTime)+1)
which gives me the result:
0-1
1-2
2-3
etc...
the second, would be the count of total records from a second column in tblb:
insert into tbla
select @hstr,count(tbla.Inbound)
from tblb
where start_time>@starttime
and start_time <dateadd(hour,1,@startTime)
So, the table would look like this:
Hour Count
0-1 1
1-2 5
2-3 4
The above works fine when I the start date begin time and end time are witin a 24 hour period. However, when the start date/time beginning and end are more then 24 hours, I get duplicate results.
Im stumped on this one. I do not know how to take a sum of the total for the hours (say 0-1 over a 48 hour period).
What is the SQL Function that would allow me to calculate the total amount of records in a table column between dates?
I think the problem is with the dateadd function, but am not sure. Can anyone help?
If I have two columns, the first is a SQL function to provide the time from hour to hour:
declare @HStr int
set @HStr = convert(varchar,datepart(hour,@startTime))+'
- '+convert(varchar,datepart(hour,@startTime)+1)
which gives me the result:
0-1
1-2
2-3
etc...
the second, would be the count of total records from a second column in tblb:
insert into tbla
select @hstr,count(tbla.Inbound)
from tblb
where start_time>@starttime
and start_time <dateadd(hour,1,@startTime)
So, the table would look like this:
Hour Count
0-1 1
1-2 5
2-3 4
The above works fine when I the start date begin time and end time are witin a 24 hour period. However, when the start date/time beginning and end are more then 24 hours, I get duplicate results.
Im stumped on this one. I do not know how to take a sum of the total for the hours (say 0-1 over a 48 hour period).
What is the SQL Function that would allow me to calculate the total amount of records in a table column between dates?
I think the problem is with the dateadd function, but am not sure. Can anyone help?