pombas....
ainda bem que c tava usando firebird... o estrago foi pequeno... só uma mensagem de erro....
c voce tivesse usando ORACLE tinha formatado a sua maquina...
brincadeirinha....
se voce ainba estiver precisando rodar o SQL
aconselho quebrar em views o que der e/ou StoredProcedures...
select a.codigo,a.nome,t.nome as tipo,a.ativo ,case when (select count(*) from cad_reserva_apto r where ( r.checkin ='N' or r.checkin is null ) and r.apartamento = a.codigo and (r.data_entrada <='2009.04.01' and r.data_saida >= '2009.04.01' ))>0 then 'S' else 'N' end as res01 ,case when (select count(*) from cad_checkin_apto r where r.apartamento =a.codigo and (r.data_entrada <='2009.04.01' and r.data_saida >= '2009.04.01' ))>0 then 'S' else 'N' end as ocu01 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='MANUTENÇÃO' and ((r.data_entrada <='2009.04.01' and r.data_saida >= '2009.04.01' )))>0 then 'S' else 'N' end as Man01 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='BLOQUEIO' and ((r.data_entrada <='2009.04.01' and r.data_saida >= '2009.04.01' )))>0 then 'S' else 'N' end as Blo01 ,case when (select count(*) from cad_reserva_apto r where ( r.checkin ='N' or r.checkin is null ) and r.apartamento = a.codigo and (r.data_entrada <='2009.04.02' and r.data_saida >= '2009.04.02' ))>0 then 'S' else 'N' end as res02 ,case when (select count(*) from cad_checkin_apto r where r.apartamento =a.codigo and (r.data_entrada <='2009.04.02' and r.data_saida >= '2009.04.02' ))>0 then 'S' else 'N' end as ocu02 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='MANUTENÇÃO' and ((r.data_entrada <='2009.04.02' and r.data_saida >= '2009.04.02' )))>0 then 'S' else 'N' end as Man02 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='BLOQUEIO' and ((r.data_entrada <='2009.04.02' and r.data_saida >= '2009.04.02' )))>0 then 'S' else 'N' end as Blo02 ,case when (select count(*) from cad_reserva_apto r where ( r.checkin ='N' or r.checkin is null ) and r.apartamento = a.codigo and (r.data_entrada <='2009.04.03' and r.data_saida >= '2009.04.03' ))>0 then 'S' else 'N' end as res03 ,case when (select count(*) from cad_checkin_apto r where r.apartamento =a.codigo and (r.data_entrada <='2009.04.03' and r.data_saida >= '2009.04.03' ))>0 then 'S' else 'N' end as ocu03 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='MANUTENÇÃO' and ((r.data_entrada <='2009.04.03' and r.data_saida >= '2009.04.03' )))>0 then 'S' else 'N' end as Man03 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='BLOQUEIO' and ((r.data_entrada <='2009.04.03' and r.data_saida >= '2009.04.03' )))>0 then 'S' else 'N' end as Blo03 ,case when (select count(*) from cad_reserva_apto r where ( r.checkin ='N' or r.checkin is null ) and r.apartamento = a.codigo and (r.data_entrada <='2009.04.04' and r.data_saida >= '2009.04.04' ))>0 then 'S' else 'N' end as res04 ,case when (select count(*) from cad_checkin_apto r where r.apartamento =a.codigo and (r.data_entrada <='2009.04.04' and r.data_saida >= '2009.04.04' ))>0 then 'S' else 'N' end as ocu04 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='MANUTENÇÃO' and ((r.data_entrada <='2009.04.04' and r.data_saida >= '2009.04.04' )))>0 then 'S' else 'N' end as Man04 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='BLOQUEIO' and ((r.data_entrada <='2009.04.04' and r.data_saida >= '2009.04.04' )))>0 then 'S' else 'N' end as Blo04 ,case when (select count(*) from cad_reserva_apto r where ( r.checkin ='N' or r.checkin is null ) and r.apartamento = a.codigo and (r.data_entrada <='2009.04.05' and r.data_saida >= '2009.04.05' ))>0 then 'S' else 'N' end as res05 ,case when (select count(*) from cad_checkin_apto r where r.apartamento =a.codigo and (r.data_entrada <='2009.04.05' and r.data_saida >= '2009.04.05' ))>0 then 'S' else 'N' end as ocu05 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='MANUTENÇÃO' and ((r.data_entrada <='2009.04.05' and r.data_saida >= '2009.04.05' )))>0 then 'S' else 'N' end as Man05 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='BLOQUEIO' and ((r.data_entrada <='2009.04.05' and r.data_saida >= '2009.04.05' )))>0 then 'S' else 'N' end as Blo05 ,case when (select count(*) from cad_reserva_apto r where ( r.checkin ='N' or r.checkin is null ) and r.apartamento = a.codigo and (r.data_entrada <='2009.04.06' and r.data_saida >= '2009.04.06' ))>0 then 'S' else 'N' end as res06 ,case when (select count(*) from cad_checkin_apto r where r.apartamento =a.codigo and (r.data_entrada <='2009.04.06' and r.data_saida >= '2009.04.06' ))>0 then 'S' else 'N' end as ocu06 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='MANUTENÇÃO' and ((r.data_entrada <='2009.04.06' and r.data_saida >= '2009.04.06' )))>0 then 'S' else 'N' end as Man06 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='BLOQUEIO' and ((r.data_entrada <='2009.04.06' and r.data_saida >= '2009.04.06' )))>0 then 'S' else 'N' end as Blo06 ,case when (select count(*) from cad_reserva_apto r where ( r.checkin ='N' or r.checkin is null ) and r.apartamento = a.codigo and (r.data_entrada <='2009.04.07' and r.data_saida >= '2009.04.07' ))>0 then 'S' else 'N' end as res07 ,case when (select count(*) from cad_checkin_apto r where r.apartamento =a.codigo and (r.data_entrada <='2009.04.07' and r.data_saida >= '2009.04.07' ))>0 then 'S' else 'N' end as ocu07 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='MANUTENÇÃO' and ((r.data_entrada <='2009.04.07' and r.data_saida >= '2009.04.07' )))>0 then 'S' else 'N' end as Man07 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='BLOQUEIO' and ((r.data_entrada <='2009.04.07' and r.data_saida >= '2009.04.07' )))>0 then 'S' else 'N' end as Blo07 ,case when (select count(*) from cad_reserva_apto r where ( r.checkin ='N' or r.checkin is null ) and r.apartamento = a.codigo and (r.data_entrada <='2009.04.08' and r.data_saida >= '2009.04.08' ))>0 then 'S' else 'N' end as res08 ,case when (select count(*) from cad_checkin_apto r where r.apartamento =a.codigo and (r.data_entrada <='2009.04.08' and r.data_saida >= '2009.04.08' ))>0 then 'S' else 'N' end as ocu08 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='MANUTENÇÃO' and ((r.data_entrada <='2009.04.08' and r.data_saida >= '2009.04.08' )))>0 then 'S' else 'N' end as Man08 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='BLOQUEIO' and ((r.data_entrada <='2009.04.08' and r.data_saida >= '2009.04.08' )))>0 then 'S' else 'N' end as Blo08 ,case when (select count(*) from cad_reserva_apto r where ( r.checkin ='N' or r.checkin is null ) and r.apartamento = a.codigo and (r.data_entrada <='2009.04.09' and r.data_saida >= '2009.04.09' ))>0 then 'S' else 'N' end as res09 ,case when (select count(*) from cad_checkin_apto r where r.apartamento =a.codigo and (r.data_entrada <='2009.04.09' and r.data_saida >= '2009.04.09' ))>0 then 'S' else 'N' end as ocu09 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='MANUTENÇÃO' and ((r.data_entrada <='2009.04.09' and r.data_saida >= '2009.04.09' )))>0 then 'S' else 'N' end as Man09 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='BLOQUEIO' and ((r.data_entrada <='2009.04.09' and r.data_saida >= '2009.04.09' )))>0 then 'S' else 'N' end as Blo09 ,case when (select count(*) from cad_reserva_apto r where ( r.checkin ='N' or r.checkin is null ) and r.apartamento = a.codigo and (r.data_entrada <='2009.04.10' and r.data_saida >= '2009.04.10' ))>0 then 'S' else 'N' end as res10 ,case when (select count(*) from cad_checkin_apto r where r.apartamento =a.codigo and (r.data_entrada <='2009.04.10' and r.data_saida >= '2009.04.10' ))>0 then 'S' else 'N' end as ocu10 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='MANUTENÇÃO' and ((r.data_entrada <='2009.04.10' and r.data_saida >= '2009.04.10' )))>0 then 'S' else 'N' end as Man10 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='BLOQUEIO' and ((r.data_entrada <='2009.04.10' and r.data_saida >= '2009.04.10' )))>0 then 'S' else 'N' end as Blo10 ,case when (select count(*) from cad_reserva_apto r where ( r.checkin ='N' or r.checkin is null ) and r.apartamento = a.codigo and (r.data_entrada <='2009.04.11' and r.data_saida >= '2009.04.11' ))>0 then 'S' else 'N' end as res11 ,case when (select count(*) from cad_checkin_apto r where r.apartamento =a.codigo and (r.data_entrada <='2009.04.11' and r.data_saida >= '2009.04.11' ))>0 then 'S' else 'N' end as ocu11 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='MANUTENÇÃO' and ((r.data_entrada <='2009.04.11' and r.data_saida >= '2009.04.11' )))>0 then 'S' else 'N' end as Man11 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='BLOQUEIO' and ((r.data_entrada <='2009.04.11' and r.data_saida >= '2009.04.11' )))>0 then 'S' else 'N' end as Blo11 ,case when (select count(*) from cad_reserva_apto r where ( r.checkin ='N' or r.checkin is null ) and r.apartamento = a.codigo and (r.data_entrada <='2009.04.12' and r.data_saida >= '2009.04.12' ))>0 then 'S' else 'N' end as res12 ,case when (select count(*) from cad_checkin_apto r where r.apartamento =a.codigo and (r.data_entrada <='2009.04.12' and r.data_saida >= '2009.04.12' ))>0 then 'S' else 'N' end as ocu12 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='MANUTENÇÃO' and ((r.data_entrada <='2009.04.12' and r.data_saida >= '2009.04.12' )))>0 then 'S' else 'N' end as Man12 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='BLOQUEIO' and ((r.data_entrada <='2009.04.12' and r.data_saida >= '2009.04.12' )))>0 then 'S' else 'N' end as Blo12 ,case when (select count(*) from cad_reserva_apto r where ( r.checkin ='N' or r.checkin is null ) and r.apartamento = a.codigo and (r.data_entrada <='2009.04.13' and r.data_saida >= '2009.04.13' ))>0 then 'S' else 'N' end as res13 ,case when (select count(*) from cad_checkin_apto r where r.apartamento =a.codigo and (r.data_entrada <='2009.04.13' and r.data_saida >= '2009.04.13' ))>0 then 'S' else 'N' end as ocu13 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='MANUTENÇÃO' and ((r.data_entrada <='2009.04.13' and r.data_saida >= '2009.04.13' )))>0 then 'S' else 'N' end as Man13 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='BLOQUEIO' and ((r.data_entrada <='2009.04.13' and r.data_saida >= '2009.04.13' )))>0 then 'S' else 'N' end as Blo13 ,case when (select count(*) from cad_reserva_apto r where ( r.checkin ='N' or r.checkin is null ) and r.apartamento = a.codigo and (r.data_entrada <='2009.04.14' and r.data_saida >= '2009.04.14' ))>0 then 'S' else 'N' end as res14 ,case when (select count(*) from cad_checkin_apto r where r.apartamento =a.codigo and (r.data_entrada <='2009.04.14' and r.data_saida >= '2009.04.14' ))>0 then 'S' else 'N' end as ocu14 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='MANUTENÇÃO' and ((r.data_entrada <='2009.04.14' and r.data_saida >= '2009.04.14' )))>0 then 'S' else 'N' end as Man14 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='BLOQUEIO' and ((r.data_entrada <='2009.04.14' and r.data_saida >= '2009.04.14' )))>0 then 'S' else 'N' end as Blo14 ,case when (select count(*) from cad_reserva_apto r where ( r.checkin ='N' or r.checkin is null ) and r.apartamento = a.codigo and (r.data_entrada <='2009.04.15' and r.data_saida >= '2009.04.15' ))>0 then 'S' else 'N' end as res15 ,case when (select count(*) from cad_checkin_apto r where r.apartamento =a.codigo and (r.data_entrada <='2009.04.15' and r.data_saida >= '2009.04.15' ))>0 then 'S' else 'N' end as ocu15 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='MANUTENÇÃO' and ((r.data_entrada <='2009.04.15' and r.data_saida >= '2009.04.15' )))>0 then 'S' else 'N' end as Man15 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='BLOQUEIO' and ((r.data_entrada <='2009.04.15' and r.data_saida >= '2009.04.15' )))>0 then 'S' else 'N' end as Blo15 ,case when (select count(*) from cad_reserva_apto r where ( r.checkin ='N' or r.checkin is null ) and r.apartamento = a.codigo and (r.data_entrada <='2009.04.16' and r.data_saida >= '2009.04.16' ))>0 then 'S' else 'N' end as res16 ,case when (select count(*) from cad_checkin_apto r where r.apartamento =a.codigo and (r.data_entrada <='2009.04.16' and r.data_saida >= '2009.04.16' ))>0 then 'S' else 'N' end as ocu16 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='MANUTENÇÃO' and ((r.data_entrada <='2009.04.16' and r.data_saida >= '2009.04.16' )))>0 then 'S' else 'N' end as Man16 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='BLOQUEIO' and ((r.data_entrada <='2009.04.16' and r.data_saida >= '2009.04.16' )))>0 then 'S' else 'N' end as Blo16 ,case when (select count(*) from cad_reserva_apto r where ( r.checkin ='N' or r.checkin is null ) and r.apartamento = a.codigo and (r.data_entrada <='2009.04.17' and r.data_saida >= '2009.04.17' ))>0 then 'S' else 'N' end as res17 ,case when (select count(*) from cad_checkin_apto r where r.apartamento =a.codigo and (r.data_entrada <='2009.04.17' and r.data_saida >= '2009.04.17' ))>0 then 'S' else 'N' end as ocu17 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='MANUTENÇÃO' and ((r.data_entrada <='2009.04.17' and r.data_saida >= '2009.04.17' )))>0 then 'S' else 'N' end as Man17 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='BLOQUEIO' and ((r.data_entrada <='2009.04.17' and r.data_saida >= '2009.04.17' )))>0 then 'S' else 'N' end as Blo17 ,case when (select count(*) from cad_reserva_apto r where ( r.checkin ='N' or r.checkin is null ) and r.apartamento = a.codigo and (r.data_entrada <='2009.04.18' and r.data_saida >= '2009.04.18' ))>0 then 'S' else 'N' end as res18 ,case when (select count(*) from cad_checkin_apto r where r.apartamento =a.codigo and (r.data_entrada <='2009.04.18' and r.data_saida >= '2009.04.18' ))>0 then 'S' else 'N' end as ocu18 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='MANUTENÇÃO' and ((r.data_entrada <='2009.04.18' and r.data_saida >= '2009.04.18' )))>0 then 'S' else 'N' end as Man18 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='BLOQUEIO' and ((r.data_entrada <='2009.04.18' and r.data_saida >= '2009.04.18' )))>0 then 'S' else 'N' end as Blo18 ,case when (select count(*) from cad_reserva_apto r where ( r.checkin ='N' or r.checkin is null ) and r.apartamento = a.codigo and (r.data_entrada <='2009.04.19' and r.data_saida >= '2009.04.19' ))>0 then 'S' else 'N' end as res19 ,case when (select count(*) from cad_checkin_apto r where r.apartamento =a.codigo and (r.data_entrada <='2009.04.19' and r.data_saida >= '2009.04.19' ))>0 then 'S' else 'N' end as ocu19 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='MANUTENÇÃO' and ((r.data_entrada <='2009.04.19' and r.data_saida >= '2009.04.19' )))>0 then 'S' else 'N' end as Man19 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='BLOQUEIO' and ((r.data_entrada <='2009.04.19' and r.data_saida >= '2009.04.19' )))>0 then 'S' else 'N' end as Blo19 ,case when (select count(*) from cad_reserva_apto r where ( r.checkin ='N' or r.checkin is null ) and r.apartamento = a.codigo and (r.data_entrada <='2009.04.20' and r.data_saida >= '2009.04.20' ))>0 then 'S' else 'N' end as res20 ,case when (select count(*) from cad_checkin_apto r where r.apartamento =a.codigo and (r.data_entrada <='2009.04.20' and r.data_saida >= '2009.04.20' ))>0 then 'S' else 'N' end as ocu20 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='MANUTENÇÃO' and ((r.data_entrada <='2009.04.20' and r.data_saida >= '2009.04.20' )))>0 then 'S' else 'N' end as Man20 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='BLOQUEIO' and ((r.data_entrada <='2009.04.20' and r.data_saida >= '2009.04.20' )))>0 then 'S' else 'N' end as Blo20 ,case when (select count(*) from cad_reserva_apto r where ( r.checkin ='N' or r.checkin is null ) and r.apartamento = a.codigo and (r.data_entrada <='2009.04.21' and r.data_saida >= '2009.04.21' ))>0 then 'S' else 'N' end as res21 ,case when (select count(*) from cad_checkin_apto r where r.apartamento =a.codigo and (r.data_entrada <='2009.04.21' and r.data_saida >= '2009.04.21' ))>0 then 'S' else 'N' end as ocu21 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='MANUTENÇÃO' and ((r.data_entrada <='2009.04.21' and r.data_saida >= '2009.04.21' )))>0 then 'S' else 'N' end as Man21 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='BLOQUEIO' and ((r.data_entrada <='2009.04.21' and r.data_saida >= '2009.04.21' )))>0 then 'S' else 'N' end as Blo21 ,case when (select count(*) from cad_reserva_apto r where ( r.checkin ='N' or r.checkin is null ) and r.apartamento = a.codigo and (r.data_entrada <='2009.04.22' and r.data_saida >= '2009.04.22' ))>0 then 'S' else 'N' end as res22 ,case when (select count(*) from cad_checkin_apto r where r.apartamento =a.codigo and (r.data_entrada <='2009.04.22' and r.data_saida >= '2009.04.22' ))>0 then 'S' else 'N' end as ocu22 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='MANUTENÇÃO' and ((r.data_entrada <='2009.04.22' and r.data_saida >= '2009.04.22' )))>0 then 'S' else 'N' end as Man22 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='BLOQUEIO' and ((r.data_entrada <='2009.04.22' and r.data_saida >= '2009.04.22' )))>0 then 'S' else 'N' end as Blo22 ,case when (select count(*) from cad_reserva_apto r where ( r.checkin ='N' or r.checkin is null ) and r.apartamento = a.codigo and (r.data_entrada <='2009.04.23' and r.data_saida >= '2009.04.23' ))>0 then 'S' else 'N' end as res23 ,case when (select count(*) from cad_checkin_apto r where r.apartamento =a.codigo and (r.data_entrada <='2009.04.23' and r.data_saida >= '2009.04.23' ))>0 then 'S' else 'N' end as ocu23 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='MANUTENÇÃO' and ((r.data_entrada <='2009.04.23' and r.data_saida >= '2009.04.23' )))>0 then 'S' else 'N' end as Man23 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='BLOQUEIO' and ((r.data_entrada <='2009.04.23' and r.data_saida >= '2009.04.23' )))>0 then 'S' else 'N' end as Blo23 ,case when (select count(*) from cad_reserva_apto r where ( r.checkin ='N' or r.checkin is null ) and r.apartamento = a.codigo and (r.data_entrada <='2009.04.24' and r.data_saida >= '2009.04.24' ))>0 then 'S' else 'N' end as res24 ,case when (select count(*) from cad_checkin_apto r where r.apartamento =a.codigo and (r.data_entrada <='2009.04.24' and r.data_saida >= '2009.04.24' ))>0 then 'S' else 'N' end as ocu24 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='MANUTENÇÃO' and ((r.data_entrada <='2009.04.24' and r.data_saida >= '2009.04.24' )))>0 then 'S' else 'N' end as Man24 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='BLOQUEIO' and ((r.data_entrada <='2009.04.24' and r.data_saida >= '2009.04.24' )))>0 then 'S' else 'N' end as Blo24 ,case when (select count(*) from cad_reserva_apto r where ( r.checkin ='N' or r.checkin is null ) and r.apartamento = a.codigo and (r.data_entrada <='2009.04.25' and r.data_saida >= '2009.04.25' ))>0 then 'S' else 'N' end as res25 ,case when (select count(*) from cad_checkin_apto r where r.apartamento =a.codigo and (r.data_entrada <='2009.04.25' and r.data_saida >= '2009.04.25' ))>0 then 'S' else 'N' end as ocu25 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='MANUTENÇÃO' and ((r.data_entrada <='2009.04.25' and r.data_saida >= '2009.04.25' )))>0 then 'S' else 'N' end as Man25 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='BLOQUEIO' and ((r.data_entrada <='2009.04.25' and r.data_saida >= '2009.04.25' )))>0 then 'S' else 'N' end as Blo25 ,case when (select count(*) from cad_reserva_apto r where ( r.checkin ='N' or r.checkin is null ) and r.apartamento = a.codigo and (r.data_entrada <='2009.04.26' and r.data_saida >= '2009.04.26' ))>0 then 'S' else 'N' end as res26 ,case when (select count(*) from cad_checkin_apto r where r.apartamento =a.codigo and (r.data_entrada <='2009.04.26' and r.data_saida >= '2009.04.26' ))>0 then 'S' else 'N' end as ocu26 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='MANUTENÇÃO' and ((r.data_entrada <='2009.04.26' and r.data_saida >= '2009.04.26' )))>0 then 'S' else 'N' end as Man26 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='BLOQUEIO' and ((r.data_entrada <='2009.04.26' and r.data_saida >= '2009.04.26' )))>0 then 'S' else 'N' end as Blo26 ,case when (select count(*) from cad_reserva_apto r where ( r.checkin ='N' or r.checkin is null ) and r.apartamento = a.codigo and (r.data_entrada <='2009.04.27' and r.data_saida >= '2009.04.27' ))>0 then 'S' else 'N' end as res27 ,case when (select count(*) from cad_checkin_apto r where r.apartamento =a.codigo and (r.data_entrada <='2009.04.27' and r.data_saida >= '2009.04.27' ))>0 then 'S' else 'N' end as ocu27 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='MANUTENÇÃO' and ((r.data_entrada <='2009.04.27' and r.data_saida >= '2009.04.27' )))>0 then 'S' else 'N' end as Man27 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='BLOQUEIO' and ((r.data_entrada <='2009.04.27' and r.data_saida >= '2009.04.27' )))>0 then 'S' else 'N' end as Blo27 ,case when (select count(*) from cad_reserva_apto r where ( r.checkin ='N' or r.checkin is null ) and r.apartamento = a.codigo and (r.data_entrada <='2009.04.28' and r.data_saida >= '2009.04.28' ))>0 then 'S' else 'N' end as res28 ,case when (select count(*) from cad_checkin_apto r where r.apartamento =a.codigo and (r.data_entrada <='2009.04.28' and r.data_saida >= '2009.04.28' ))>0 then 'S' else 'N' end as ocu28 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='MANUTENÇÃO' and ((r.data_entrada <='2009.04.28' and r.data_saida >= '2009.04.28' )))>0 then 'S' else 'N' end as Man28 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='BLOQUEIO' and ((r.data_entrada <='2009.04.28' and r.data_saida >= '2009.04.28' )))>0 then 'S' else 'N' end as Blo28 ,case when (select count(*) from cad_reserva_apto r where ( r.checkin ='N' or r.checkin is null ) and r.apartamento = a.codigo and (r.data_entrada <='2009.04.29' and r.data_saida >= '2009.04.29' ))>0 then 'S' else 'N' end as res29 ,case when (select count(*) from cad_checkin_apto r where r.apartamento =a.codigo and (r.data_entrada <='2009.04.29' and r.data_saida >= '2009.04.29' ))>0 then 'S' else 'N' end as ocu29 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='MANUTENÇÃO' and ((r.data_entrada <='2009.04.29' and r.data_saida >= '2009.04.29' )))>0 then 'S' else 'N' end as Man29 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='BLOQUEIO' and ((r.data_entrada <='2009.04.29' and r.data_saida >= '2009.04.29' )))>0 then 'S' else 'N' end as Blo29 ,case when (select count(*) from cad_reserva_apto r where ( r.checkin ='N' or r.checkin is null ) and r.apartamento = a.codigo and (r.data_entrada <='2009.04.30' and r.data_saida >= '2009.04.30' ))>0 then 'S' else 'N' end as res30 ,case when (select count(*) from cad_checkin_apto r where r.apartamento =a.codigo and (r.data_entrada <='2009.04.30' and r.data_saida >= '2009.04.30' ))>0 then 'S' else 'N' end as ocu30 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='MANUTENÇÃO' and ((r.data_entrada <='2009.04.30' and r.data_saida >= '2009.04.30' )))>0 then 'S' else 'N' end as Man30 ,case when (select count(*) from hot_manutencao_apto r inner join hot_manutencao h on (r.codigo=h.codigo) where r.apartamento =a.codigo and h.tipo='BLOQUEIO' and ((r.data_entrada <='2009.04.30' and r.data_saida >= '2009.04.30' )))>0 then 'S' else 'N' end as Blo30 from cad_apartamento a inner join cad_tipo_apto t on a.tipo = t.codigo left join cad_checkin_apto r on r.apartamento = a.codigo and (r.mudanca_hospedagem ='N' or r.mudanca_hospedagem is null ) and r.fechado='N' order by t.nome,a.codigo
--
Atenciosamente,
Jeudí Prando
--------------------------------------------------------------
agora melhorou...