Friday, 15 August 2014

sql server 2008 - How to select a row where from and to date are exist in SQL DB -



sql server 2008 - How to select a row where from and to date are exist in SQL DB -

hello have sql table this:

reservationroom: id name fromdate todate 5 room1 2012-11-29 11:46:00.000 2012-11-29 12:45:00.000 6 room1 2012-11-29 12:55:00.000 2012-11-29 14:20:00.000 7 room1 2012-11-29 15:00:00.000 2012-11-29 16:42:00.000

i have , date , want select rooms between 2 dates.

example:

form date: 2012-11-29 11:50:00.000 date: 2012-11-29 13:46:00.000

the output should this:

reservationroom:

id name fromdate todate 5 room1 2012-11-29 11:46:00.000 2012-11-29 12:45:00.000 6 room1 2012-11-29 12:55:00.000 2012-11-29 14:20:00.000

this have far:

select* reservationroom fromdate between convert(datetime,'2012-11-29 11:50:00.000',101) , convert(datetime,'2012-11-29 13:46:00.000',101) , todate < convert(datetime,'2012-11-29 13:46:00.000',101) order fromdate asc

my select statement filters much , cant see dates between 2 dates.

am missing something?

thanks in advance help

sorry convert comment, thought datetime varchar convert. input date, gave 2 date , table has 2 date each room. confusing these dates , dates. illustration output, should utilize or between 2 filter. here. luck.

select * table1 (convert(datetime, @from, 101) between fromdate , todate) or (convert(datetime, @to, 101) between fromdate , todate)

sql sql-server-2008 datetime select

No comments:

Post a Comment