sql insert statement with a lot of same where clause and one different where cluase

Posted by william on Stack Overflow See other posts from Stack Overflow or by william
Published on 2010-12-31T06:41:03Z Indexed on 2010/12/31 7:53 UTC
Read the original article Hit count: 191

Filed under:

I m sry if the title is not clear.

Here's my proble.

I created a new table which will show total, average and maximum values.

I have to insert the results into that table.

That table will have only 4 rows. No Appointment, Appointment Early, Appointment Late and Appointment Punctual.

So.. I have sth like..

insert into newTable
select
'No Appointment' as 'Col1',
avg statement,
total statement,
max statement 
from orgTable
where (general conditions) and (unique condition to check NO APPOINTMENT);

I have to do that same thing for another 3 rows.. where only the unique condition is different to check early, punctual or late..

So..the statement is super long.

I wanna reduce the size.. How can I achieve that?

© Stack Overflow or respective owner

Related posts about sql-server