dim msel as string msel="select " msel=msel+"(case when datediff(dd,pdata,getdate())>15 then '15.+ de 15 dias' else (case when datediff(dd,pdata,getdate())<=15 and datediff(dd,pdata,getdate())> 7 then " msel=msel+"'08.de 7 a 15 dias' else '0'+convert(char(3),datediff(dd,pdata,getdate()))+' dias' end ) end ) as Idade," msel=msel+" count(*) as Numero" msel=msel+" from pa (nolock) where pa.fechado=0 and pa.nosug=0 and CASS='NORTE' and ((select count(*) from mh (nolock) where mh.nopat=pa.nopat)=0) group by (case when nosug<>0 then 'Sim' else ' ' end)," msel=msel+"(case when datediff(dd,pdata,getdate())>15 then '15.+ de 15 dias' else (case when datediff(dd,pdata,getdate())<=15 and datediff(dd,pdata,getdate())>7 then " msel=msel+"'08.de 7 a 15 dias' else '0'+convert(char(3),datediff(dd,pdata,getdate()))+' dias' end ) end ),pdata " msel=msel+" order by (case when nosug<>0 then 'Sim' else ' ' end)," msel=msel+"(case when datediff(dd,pdata,getdate())>15 then '15.+ de 15 dias' else (case when datediff(dd,pdata,getdate())<=15 and datediff(dd,pdata,getdate())>7 then " msel=msel+"'08.de 7 a 15 dias' else '0'+convert(char(3),datediff(dd,pdata,getdate()))+' dias' end ) end )"
dim ds as system.data.datatable=webcontrollib.cdata.getdatatable(msel)
return ds |