This is my table data.
| 27 | 2011-05-30 00:00:00.000 | 2011-05-31 00:00:00.000 | 2011-05-30 00:00:00.000 | meeting | description | Violet | CornflowerBlue | NULL | NULL | 1 | 6 PM | 8 PM | Guntur |
| 28 | 2011-06-05 00:00:00.000 | 2011-06-07 00:00:00.000 | 2011-06-01 00:00:00.000 | discussion | meeting | SteelBlue | Beige | 1 | 1 | 1 | 4 PM | 5 PM | Hyderabad |
Just concentrate these columns i.e EventStartDate,EventEndDate,StartTime and EndTime.
I am selecting EventStartDate,EventEndDate,StartTime and EndTime.
So two records are available in the table.
Next time I am selecting EventStartDate,EventEndDate,StartTime and EndTime
Suppose data present between the dates and timings It has to return the data otherwise doesn't return.
I want that Query.

Dorababu MekaPosted May 31, 2011, 6:40 AM
Dorababu MekaPosted May 31, 2011, 7:25 AM
Dorababu MekaPosted May 26, 2011, 7:29 AM
Mahesh BabuPosted May 26, 2011, 7:27 AM
Thank u Dorababu.
Dorababu MekaPosted May 26, 2011, 6:28 AM
Dorababu MekaPosted May 19, 2011, 8:55 AM
As per your posted query try this
select * from tblEvents where
EventStartDate between '2011-05-31' and '2011-06-01'
or EventEndDate between '2011-05-31' and '2011-06-01'
And StartTime
between '1 PM' and '9 PM' or EndTime between '1 PM' and'9 PM'
Mahesh BabuPosted May 19, 2011, 8:52 AM
that snap shot is my table data of four columns.
I want to check the condition.
this is my query ,see
select * from tbl_Events where EventStartDate between '2011-05-31' and '2011-06-01' and EventEndDate between '2011-05-31' and '2011-06-01' And StartTime between '1 PM' and '9 PM' and EndTime between '1 PM' and'9 PM'
Actually the table contained Starttime and EndTime is 6 PM , 8 PM.
Now When i execute the query it has to return the data. But it didn't return the data.
Dorababu MekaPosted May 19, 2011, 8:49 AM
select * from tblEvents
where EventStartDate
between '2011-05-31' and '2011-06-05'
or EventEndDate between '2011-05-31'
and '2011-06-08' And StartTime
between '1 PM' and '9 PM' or EndTime between '1 PM' and'9 PM'
Dorababu MekaPosted May 19, 2011, 8:39 AM
Mahesh BabuPosted May 19, 2011, 8:38 AM
Dorababu MekaPosted May 19, 2011, 8:31 AM
Mahesh BabuPosted May 19, 2011, 8:29 AM
select * from tbl_Events where EventStartDate between '2011-05-31' and '2011-06-01' and EventEndDate between '2011-05-31' and '2011-06-01' And StartTime between '1 PM' and '9 PM' and EndTime between '1 PM' and'9 PM'
It doesn't return data. But I want return the data between the timings
Dorababu MekaPosted May 19, 2011, 7:49 AM
My sample screens
Initial Data
After query
Dorababu MekaPosted May 19, 2011, 7:24 AM
Suthish NairPosted May 19, 2011, 7:05 AM
Mahesh BabuPosted May 19, 2011, 6:47 AM
see this one.
select * from tbl_Events where EventStartDate between '2011-05-31' and '2011-06-01' and EventEndDate between '2011-05-31' and '2011-06-01' And StartTime between '1 PM' and '8 PM' and EndTime between '1 PM' and'8 PM'
When I am using 30th date I got the data. But When I am using 31 date I didnt get the data.
In this case also I want data.
Posted May 19, 2011, 6:36 AM
select * from tbl_Events where EventStartDate in('2011-05-31','2011-06-01') and EventEndDate in('2011-05-31','2011-06-01') And StartTime between '2 PM' and '9 PM' and EndTime between '2 PM' and '9 PM'
I haven't tested the quest. Just for syntax error.
Mahesh BabuPosted May 19, 2011, 6:28 AM
I writen query like this,see
ALTER procedure [dbo].[sp_GetEventTimings](@EventStartTime varchar(50),@EventEndTime varchar(50),@EventStartDate datetime,@EventEndDate datetime)
as
begin
select * from tbl_Events where EventStartDate in(@EventStartDate,@EventEndDate) and EventEndDate in(@EventStartDate,@EventEndDate) And StartTime in (@EventStartTime,@EventEndTime) and EndTime in(@EventStartTime,@EventEndTime)
end
Ex: select * from tbl_Events where EventStartDate in('2011-05-30','2011-05-31') and EventEndDate in('2011-05-30','2011-05-31') And StartTime in ('6 PM','8 PM') and EndTime in('6 PM','8 PM')
The above query returns data.
Suppose the query is like this,
Ex: select * from tbl_Events where EventStartDate in('2011-05-31','2011-06-01') and EventEndDate in('2011-05-31','2011-06-01') And StartTime in ('2 PM','9 PM') and EndTime in ('2 PM','9 PM')
The above query doesn't returns the data.
But I want to return data . Because 6 Pm to 8 Pm already available.
Suthish NairPosted May 19, 2011, 6:04 AM
Mahesh BabuPosted May 19, 2011, 5:58 AM
I alredy sent the table. In the first record already event is there on 3oth and 31th and timings also there.
Now suppose I selected date from 2011-05-27 to 2011-05-02 time from 11 AM to 8 PM, It should be return msg
"Event already Exist, so select different dates and different timings" .
I want quert for that one.
Abhimanyu K VatsaPosted May 19, 2011, 4:27 AM
http://www.c-sharpcorner.com/Forums/Thread/123218/get-specific-data-from-other-database-tables.aspx
Dorababu MekaPosted May 19, 2011, 4:17 AM
can you clearly tell the desired output it is hard to understand or post the output that you want so we will try our best