Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Retreive records within timeslots

Author  Topic 

Kavitha_BE
Starting Member

1 Post

Posted - 2009-08-20 : 02:30:13
hi..
i want to write a query.
suppose the table contains records for dated 2009-08-20 and time between 8:00 to 12:00. and again if trying to insert data for same date in between 9:00 to 10:00 means it should not allow.. so before inserting the query has to check if there is any data in that time.
it similar to check whether doctor is free in between time slots to get an doctor appointment.

Thanks in advance

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-08-20 : 02:43:55
how do you stored the appointment time in the table ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-08-20 : 02:46:32
try this

create table #mytable (id int,fromtime smalldatetime,totime smalldatetime)

insert into #mytable values (1,'2009-08-20 08:00:00','2009-08-20 12:00:00')

select * from #mytable

if not exists (select 'x' from #mytable where '2009-08-20 07:00:00' between fromtime and totime)
begin

-- Insert

print 'Insert statement'


End

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page
   

- Advertisement -