Sunday, November 30, 2008

SQL Optimization Question

I need some help with optimizing the following SQL script.

My goal is to produce the following table:

EmployeeNameStatus1Status2Status3
Employee ACountA1CountA2CountA3
Employee BCountB1CountB2CountB3
Employee CCountC1CountC2CountC3
TotalTotal1Total2Total3

My issues are:
  1. The script takes a couple minutes to run.
  2. It seems clunky the way I have approached by creating a temporary table

Here's my script:

Drop Table NewProjectTable
select
EM.Org,Organization.Name as Office,coalesce(em.LastName,'')+', '+coalesce(em.PreferredName,'') as Employee,
(select count(*) from ProjectTable where ProjNbr in (select ProjNbr from ProjectTable where ProjMgr=em.employee) and Status='Status1') as Status1,
(select count(*) from ProjectTable where ProjNbr in (select ProjNbr from ProjectTable where ProjMgr=em.employee) and Status='Status2') as Status2,
(select count(*) from ProjectTable where ProjNbr in (select ProjNbr from ProjectTable where ProjMgr=em.employee) and Status='Status3') as Status3,
into NewProjectTable
from
em,organization
where em.org = organization.org
and em.status = 'A'

declare @Status1Total int
declare @Status2Total int
declare @Status3Total int
select @Status1Total = count(*) from ProjectTable where Status='Status1'
select @Status2Total = count(*) from ProjectTable where Status='Status2'
select @Status3Total = count(*) from ProjectTable where Status='Status3'
insert into NewProjectTable
(Org,Office,Employee,Status1,Status2,Status3)
values (99,'Total',space(5),@Status1Total,@Status2Total,@Status3Total)

Sunday, November 23, 2008

Weekend at West Baden

My wife and I decided it was time to get away for a weekend. So the weekend before our anniversary, we went to West Baden Springs near French Lick Indiana. My boss recommended it after the hotel went through a multi-million dollar renovation recently.

When we arrived at the hotel, we were immediately taken care of with valet parking and bell services. Check-in was so quick I almost forgot the we checked in.

After checking in we proceed to the atrium. Words cannot express the dome interior and size. The dome rose six stories above the floor. It was truly amazing. Upon entering our room, we were immediately taken back by the size and luxury. The bellman showed us the balcony over-looking the atrium. Again, the beauty was amazing.

We then adjourned to the Sinclair restaurant located in the hotel. The fine dining experience was just what the doctor ordered after a long couple of weeks. The ambiance was peaceful and upscale. Throughout the meal, we felt spoiled and pampered.

The next morning we ordered room service and took our time getting ready. We then headed to the spa for our couples massage. It was my first ever massage. Not knowing what to expect, I was pleasantly surprised by the experience.

We then headed to the French Lick resort for lunch and my wife's hair salon appointment. The atmosphere was completely different. Tons of people milling about, lots of noise, and more kids than I cared to see on our relaxing weekend getaway.

We headed back to West Baden to get ready for dinner. Walking into the atrium again with the gorgeous architecture confirmed that we made the proper choice of where to stay. The atmosphere in and of it itself was relaxing and immediately diffused the hustle and bustle of French Lick.

We got dressed up and headed back over to French Lick's 1875 Steak House. My wife and I both love a good filet mignon. French Lick is just one mile from West Bade and under common ownership with. Shuttle that goes back and forth every 15 minutes.

There was certainly more activity and noise compared to the Sinclair, but was upscale none the less. The service was excellent and the steak was very good. It was not as good as Del Frisco's or Pat's Steakhouse, but overall was just as good.

We then headed back to the incredible West Baden to retire for the evening with the weekend almost over.

West Baden attracts people from all over the country including many celebrities and politicians. However, most guest arrive from Louisville, St. Louis, Indianapolis, Chicago, and every in between. If you are looking for a relaxing romantic getaway, I highly recommend West Baden. If you are looking for a little more fun and excitement, then you can hop on a shuttle to the casino at French Lick. Regardless of you purpose, I would certainly stay at West Baden.