Created
April 12, 2016 16:04
-
-
Save MarioCares/e7b6bf0ad6918e1171394f73b105e15a to your computer and use it in GitHub Desktop.
Nueva Query agregar AMI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select id_sapu, xrut, dv, min(xfecha) from | |
(select s.id_sapu, cast(rtrim(ltrim(s.rut_paciente)) as decimal) as xrut, | |
'dv', date_format(s.lblfechahoraingreso, '%Y-%m-%d') as xfecha | |
from historia_sapu as s | |
where | |
(hour(s.lblfechahoraingreso) >= 8 and hour(s.lblfechahoraingreso) <= 17) | |
and weekday(s.lblfechahoraingreso) not in (1,7) | |
and (s.lblfechahoraingreso between '2015-10-01' and '2016-03-31') | |
and s.rut_paciente not like '%-%' | |
and s.rut_paciente < 43000000 and s.rut_paciente <> 0 | |
and convert(s.rut_paciente, signed integer) is not null) as x | |
group by xrut | |
order by xrut asc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment