Query over 2 columns

  • Hi,

    I have a table that includes two DateTime columns. The first column holds the date. e.g 2006/5/10 and the second column holds time e,g 08:15:25.

    I am having a problems specifing a query that will list the rows in the table  between a date time range.

    i.e return all rows between 2006/5/8 09:00:00 and 2006/5/10 21:30:00

    Can anyone give me any suggesstions on how to do this?

    Thanks

    Macca

  • Both columns are datetime data type?  Could you post the table DDL and some sample data from the table? 


    And then again, I might be wrong ...
    David Webb

  • First I would go through the effort of creating a datetime column with the date and time mixed as you should. It will be much more efficient.

    this is clearly a schema problem. but you can still get the data out this way.

    Select *

    from Mytable

    where cast(convert(varchar(12),Date1) + ' ' + convert(varchar(12),Date2) as datetime) between @Date1 and @Date2

     

    By the way don't cross post, Most reall all boards

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply