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.
| Author |
Topic |
|
jacobmk
Starting Member
6 Posts |
Posted - 2011-08-02 : 01:45:15
|
| Hi,I have doubts in sql query.I have slots table. It basically contain maximum slots ,maximum slots for am and Pm DayName slots AM PM1 Monday 50 30 202 Tuesday 50 30 203 Wednesday 50 30 204 Thursday 50 30 205 Friday 25 25 06 Saturday 15 15 07 Sunday 0 0 0I have appointment table. This table is used for adding appointmenttable structureAppointdate iS_AM 8/7/2011 12:00:00 AM 1 8/5/2011 12:00:00 AM 1 8/6/2011 12:00:00 AM 1 8/2/2011 12:00:00 AM 1 8/2/2011 12:00:00 AM 1 8/2/2011 12:00:00 AM 0 8/3/2011 12:00:00 AM 0 8/4/2011 12:00:00 AM 1 8/4/2011 12:00:00 AM 0 If it is 1 it is Am else PM.I need to display remaining available slots for the next four days.I need to avoid sundays.How can we avoid sundays.my query so far is thiswith cte as(select dateName(dw,appoint_date) dayN,convert(varchar(12),appoint_date,101) appoint_date, sum(case is_am when 1 then 1 else 0 end) as AM, sum(case is_am when 0 then 1 else 0 end) as PM ,sum (case is_am when 0 then 1 when 1 then 1 end) as Total from pda_appoint where convert(varchar(12),appoint_date,111) between Convert(varchar(10), getdate() ,111) and Convert(varchar(10), dateadd(dd,3,getdate()) ,111) group by appoint_date )select p.AM-cte.AM as [Rem AM],p.PM-cte.PM as [Rem PM],p.slots-cte.Total as [Rem Total] from cte inner join pda_slots p on cte.dayN=day_nameOutput is as followsremMax remAm remPM28 19 4730 19 4929 19 4823 0 23I need to avoid sundays and is my sql query is correct |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-08-02 : 02:26:34
|
| for avoiding sundays just use where condition like where dateName(dw,appoint_date) <> 'Sunday'------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|