Podria alguien ayudarme con esta sentencia??
select a.rfc,b.nombre,c.programa
from (select rtrim(ltrim(rfc)) as rfc,case inc.idinc when 'I4' then 'R' end as tipo,
str(datepart(month,fech_inc),2,0)+ case(str(convert(day,fech_inc),2,0)/16) when 0 then 1 when 1 then 2 when 2 then 1 end as qna from incidencias inc
where ltrim(rtrim(inc.idinc)) ='I4' and fech_inc between convert(datetime,'01/01/2004',103) and
convert(datetime,'31/12/2004',103)-1 group by idinc, datepart(month,fech_inc) +
case str(convert(day,fech_inc),2)/16 when 0 then 1 when 1 then 2 when 2 then 1 end, ltrim(rtrim(rfc))
having count(case idinc when 'I4' then 'R' end)>3
union
select ltrim(rtrim(rfc)) as rfc,
case idinc when 'I1' then 'F' when 'I2' then 'F' when 'I3' then 'F' end as tipo,
str(datepart(month,fech_inc),2,0) + case str(datepart(day,fech_inc),2,0)/16 when 0 then 1 when 1 then 2 when 2 then 1 end as qna
from incidencias inc where (rtrim(ltrim(inc.idjus))= NULL or ltrim(rtrim(inc.idjus))='JF') and inc.idinc <>'I4' and
fech_inc between convert(datetime,'01/01/2004',103) and convert(datetime,'31/12/2004',103)-1
group by idinc,
datepart(month,fech_inc)+case(str(datepart(day,fec h_inc),2,0)/16) when 0 then 1 when 1 then 2 when 2 then 1 end,rtrim(ltrim(rfc)),
(select rfc,apellido1 +' ' +apellido2 +' '+ nombre as nombre,idprog from catperso) ,
(select idprog,programa from catprog) where rtrim(ltrim(a.rfc))=* ltrim(rtrim(b.rfc)) and ltrim(rtrim(b.idprog))= ltrim(rtrim(c.idprog))
group by a.rfc,nombre,programa order by rfc
me marca los siguientes errores.. y kisiera saber como corregirlos...
De antemano... gracias