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 MekaRank #457 · 5.5K reputationPosted May 31, 2011, 2:40 AM EDT
Dorababu MekaRank #457 · 5.5K reputationPosted May 19, 2011, 12:17 AM EDT
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
Abhimanyu K VatsaRank #14 · 51.7K reputationPosted May 19, 2011, 12:27 AM EDT
http://www.c-sharpcorner.com/Forums/Thread/123218/get-specific-data-from-other-database-tables.aspx
Mahesh BabuRank #1,089 · 1.7K reputationPosted May 19, 2011, 1:58 AM EDT
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.
Suthish NairRank #92 · 22.8K reputationPosted May 19, 2011, 2:04 AM EDT
Mahesh BabuRank #1,089 · 1.7K reputationPosted May 19, 2011, 2:28 AM EDT
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.
Posted May 19, 2011, 2:36 AM EDT
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 BabuRank #1,089 · 1.7K reputationPosted May 19, 2011, 2:47 AM EDT
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.
Suthish NairRank #92 · 22.8K reputationPosted May 19, 2011, 3:05 AM EDT
Dorababu MekaRank #457 · 5.5K reputationPosted May 19, 2011, 3:24 AM EDT
Dorababu MekaRank #457 · 5.5K reputationPosted May 19, 2011, 3:49 AM EDT
My sample screens
Initial Data
After query
Mahesh BabuRank #1,089 · 1.7K reputationPosted May 19, 2011, 4:29 AM EDT
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 MekaRank #457 · 5.5K reputationPosted May 19, 2011, 4:31 AM EDT
Mahesh BabuRank #1,089 · 1.7K reputationPosted May 19, 2011, 4:38 AM EDT
Dorababu MekaRank #457 · 5.5K reputationPosted May 19, 2011, 4:39 AM EDT
Dorababu MekaRank #457 · 5.5K reputationPosted May 19, 2011, 4:49 AM EDT
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'
Mahesh BabuRank #1,089 · 1.7K reputationPosted May 19, 2011, 4:52 AM EDT
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 MekaRank #457 · 5.5K reputationPosted May 19, 2011, 4:55 AM EDT
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'
Dorababu MekaRank #457 · 5.5K reputationPosted May 26, 2011, 2:28 AM EDT
Mahesh BabuRank #1,089 · 1.7K reputationPosted May 26, 2011, 3:27 AM EDT
Thank u Dorababu.
Dorababu MekaRank #457 · 5.5K reputationPosted May 26, 2011, 3:29 AM EDT
Dorababu MekaRank #457 · 5.5K reputationPosted May 31, 2011, 3:25 AM EDT