Often data is entered into the database as a string (varchar), when a more appropriate data type should have been applied.
Here’s a snippet of T-SQL for dealing with datetime data, stored as varchar, when what you really need is the hour.
Why would data be stored as a varchar instead of using the appropriate data type in the first place?
The most common reason might be that XML files have been loaded without any data type conversions being applied, i.e. dates have been entered as strings along with everything else.
Why would you need this code?
Should you be confronted with data in this raw string form you would be unable to apply a clause regarding a specific hour. Ideally there should be some sort of staging table to convert the fields into the appropriate data types but if you simply wanted to apply some clauses to select specific data, which will be outputted to an excel file for example, that additional effort may be unnecessary.