You need to do something like
select name
from yourTable
where time
between '3PM' and '4PM'
with a number of caveats! For one thing, this will work ONLY if your time field does in fact contain time only. If your "time" field also contains a "date" component then you will need to strip out the data component. If your "Time" field also includes a date component you can do something like:
select name
from yourTable
where time - floor(convert(float,time)) between '3PM' and '4PM'
for instance:
select getdate()
where getdate() - floor(convert(float,getdate())) between '3PM' and '4PM'
/*
-----------------------
2007-10-11 15:53:50.857
*/
You could use CONVERT along with style 108 in your WHERE clause.
You can read about CONVERT() along with its various styles in the SQL Server Books Online. I posted it, because I assume that your "time" column is of a datetime data type.
One way is something like:
declare @test table
( name varchar(20),
time datetime
)
insert into @test
select 'Barney Rubble', '2007-10-05 10:05' union all
select 'Fred Flintstone', '2007-10-05 15:45' union all
select 'Betty Rubble', '2007-10-08 15:08'
--select * from @test
select name, convert(varchar(8), time, 108) as time from @test
where time - floor(convert(float, time)) between '3PM' and '4PM'
/*
name time
-------------------- --------
Fred Flintstone 15:45:00
Betty Rubble 15:08:00
*/
select name, convert(varchar(8), time, 108) as time from @test
where time - floor(convert(float, time)) between '15:00' and '15:30'
/*
name time
-------------------- --------
Betty Rubble 15:08:00
*/
(I edited this to contain Frank's CONVERT with 108 -- his idea is a good idea.)
SELECT *
FROM your_table
WHERE CONVERT(CHAR(8), time, 108)
BETWEEN '15:00:00' AND '16:00:00'
select * from YourTable
where Time
between
cast('01/01/1900 14:00:000' as datetime) -- Change this lowest possible date
and
cast(convert(varchar(10), Getdate(), 101) +' 17:00:000' as datetime)
Bushan,
I think that 'might' include 17:01 PM on the 'lowest possible date', as well as 13:59:59 on getdate() -and a lot of other unwanted stuff inbetween ...
Ahem, this is going to return all rows between 19000101 and now and therefore is likely to produce wrong results. Only the time portion is relevant here. The date portion needs to be ignored.
Oops, my reply was aimed at Bushan's, not yours Arnie.
Use a GROUP BY, with a sum( Numbers ).
Something like:
SELECT
EmployeeID,
EmployeeTotal = sum( Numbers )
FROM MyTable
GROUP BY EmployeeID