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
 More help with Stored Procedure

Author  Topic 

awalker
Starting Member

12 Posts

Posted - 2012-08-15 : 17:08:28
Hi all

I have gotten a lot of help with this stored procedure to get it to this point, let me explain what it does then explain what I need.

The stored procedure checks if there are appointments on a particular day, if there are not any it creates appointment times based on a start time and end time from another table. What I was doing was every newly created appointment had the same IsAvailable. However now I need to check for AppointmentTime of 12:00 and have it create with IsAvailable as false. I am not sure this makes any sense at all. If it does I need help.

Thank you

if not exists(select 1 from [dbo].[Appointments] where AppointmentDate = @appointmentDate)
With TimeSlots (TimeSlot, EndTime) AS (
select StartTime, EndTime from[dbo].[AppointmentTimes] a
WHERE DayOfWeekName = DATENAME(dw, @appointmentDate)
union all
select DATEADD(hh,1,TimeSlot), EndTime
from TimeSlots
where DATEADD(hh,1,TimeSlot) <= EndTime
)
insert into [dbo].[Appointments](AppointmentTime, AppointmentTimeNonFormat, AppointmentDate, IsAvailable)
select TimeSlot, TimeSlot, @appointmentdate, @isAvailable from TimeSlots

if exists(select 1 from [dbo].[Appointments] where AppointmentDate = @appointmentDate)
select CONVERT(VarChar(15), AppointmentTime, 100) AS AppointmentTime, AppointmentTimeNonFormat, AppointmentDate, IsAvailable from [dbo].[Appointments] where AppointmentDate = @appointmentDate
else
select CONVERT(VarChar(15), AppointmentTime, 100) AS AppointmentTime, AppointmentTimeNonFormat, AppointmentDate, IsAvailable from [dbo].[Appointments] where AppointmentDate = @appointmentDate

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-15 : 22:37:35
sorry i dont understand. your if and else condition code looks the same to me.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -