All my columns are varchar so I used common expression table to convert [Column 0] to datetime since [Column 0] contains date in this format 2012-02-28 00:00:08.000
WITH pss AS
(
select CONVERT(datetime, [Column 0]) as t, [Column 1], [Column 2], [Column 3], [Column 4], [Column 5], [Column 6]
from PWS where [Column 0] like '%2/28%'
)
select *from pss where datepart(HOUR,[t]) >= '11' AND datepart(HOUR,[t]) <= '12'
I am getting the following message
Msg 242, Level 16, State 3, Line 1
The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
You also need to provide the hint with CONVERT as to the structure of the date within a varchar. The ymd sequence will be recognised as 102:
See http://msdn.microsoft.com/en-us/library/ms187928.aspx for a description of CONVERT and the available datetime styles