Created
June 26, 2015 03:48
-
-
Save NrI3/a5ff52b4ca436eb5aedf to your computer and use it in GitHub Desktop.
Procedimiento y cursor
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
| create procedure SPPAcientesXMedico | |
| @NombreMedico varchar(30) | |
| as | |
| declare | |
| @nro int, | |
| @nombrePaciente varchar(15), | |
| @fechaNacimiento date, | |
| @edad int, | |
| @enfermedad varchar(15), | |
| @diasTratamiento int, | |
| @fechaTratamiento date, | |
| @haceDias int, | |
| @especialidad varchar(15), | |
| @codPaciente int, | |
| @nroPacientes int, | |
| @fechaActual date | |
| begin | |
| declare cursor1 cursor | |
| for select p.nombre, | |
| p.fechaNacimiento, | |
| e.nombre, | |
| e.diasTratamiento, | |
| d.fecha, | |
| m.especialidad, | |
| nroPacientes | |
| from Diagnosticos d | |
| inner join Medicos m on m.cod=d.codMedico | |
| inner join Pacientes p on p.cod = d.codPaciente | |
| inner join Enfermedades e on e.cod = d.codEnfermedad | |
| where m.nombre = @NombreMedico and d.estado = 'INTERNADO' | |
| open cursor1 | |
| set @nro = 0 | |
| set @fechaActual = getdate() | |
| fetch next from cursor1 | |
| into | |
| @nombrePaciente, | |
| @fechaNacimiento, | |
| @enfermedad, | |
| @diasTratamiento, | |
| @fechaTratamiento, | |
| @especialidad, | |
| @nroPacientes | |
| if (@NombreMedico is not null and @especialidad is not null and @nroPacientes is not null) | |
| begin | |
| print ' ' | |
| print ' ' | |
| print 'CONSULTA DEL MEDICO:'+cast(@NombreMedico as char(15)) | |
| print 'ESPECIALIDAD:'+cast(@especialidad as char(15))+' '+ | |
| 'NRO PACIENTES:'+cast(@nroPacientes as char(15)) | |
| print '-------------------------------------------------------------------------------------------------------------------' | |
| print ' PACIENTES CON ESTADO DE INTERNACION' | |
| print '-------------------------------------------------------------------------------------------------------------------' | |
| print 'NRO '+ | |
| 'PACIENTE '+ | |
| 'FECHA NAC. '+ | |
| 'ENFERMEDAD '+ | |
| 'EDAD '+ | |
| 'DIAS TRAT. '+ | |
| 'FECHA TRAT. '+ | |
| 'HACE DIAS ' | |
| end | |
| else | |
| print 'No se ha encontrado las consultas del medico' | |
| while @@FETCH_STATUS = 0 | |
| begin | |
| -- print 'Entro' | |
| set @nro = @nro + 1 | |
| set @haceDias = datediff(day,@fechaTratamiento,@fechaActual) | |
| set @edad = datediff(year,@fechaNacimiento,@fechaActual) | |
| if ( month(@fechaActual)<month(@fechaNacimiento) or (month(@fechaActual)=month(@fechaNacimiento) and day(@fechaActual)<day(@fechaNacimiento)) ) | |
| set @edad = @edad - 1 | |
| print cast(@nro as char(4))+' '+ | |
| cast(@nombrePaciente as char(15))+' '+ | |
| cast(@fechaNacimiento as char(10))+' '+ | |
| cast(@enfermedad as char(15))+' '+ | |
| cast(@edad as char(4))+' '+ | |
| cast(@diasTratamiento as char(4))+' '+ | |
| cast(@fechaTratamiento as char(10))+' '+ | |
| cast(@haceDias as char(4)) | |
| fetch next from cursor1 into @nombrePaciente,@fechaNacimiento,@enfermedad,@diasTratamiento,@fechaTratamiento,@especialidad,@nroPacientes | |
| end | |
| close cursor1 | |
| deallocate cursor1 | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment