You are on page 1of 2

-- ================================================

-- Template generated from Template Explorer using:


-- Create Procedure (New Menu).SQL
--
-- Use the Specify Values for Template Parameters
-- command (Ctrl-Shift-M) to fill in the parameter
-- values below.
--
-- This block of comments will not be included in
-- the definition of the procedure.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Alejandro Cifuentes
-- Create date: <Create Date,,>
-- Description: leer las notas y marcar calificacion
-- =============================================
ALTER PROCEDURE usp_descripcion_notas

AS
BEGIN
begin tran
begin try
declare @idestudiante int, @nota decimal(2,1)

declare describirnota cursor for

select id_estudiante, nota from dbo.estudiantetarea

open describirnota

fetch next from describirnota into @idestudiante, @nota


while @@FETCH_STATUS=0
begin

if(@nota < 3)

begin
print 'El estudiante ' + cast(@idestudiante as varchar) + ', tiene una nota
baja'

end

else if (@nota between 3 and 4)

begin
print 'El estudiante ' + cast(@idestudiante as varchar) + ', tiene una nota
aceptable'
end

else if (@nota > 4 )

begin
print 'El estudiante ' + cast(@idestudiante as varchar) + ', tiene una nota
excelente'
end
fetch next from describirnota into @idestudiante, @nota

end
close describirnota

deallocate describirnota

end try

begin catch

SELECT
ERROR_NUMBER() AS ErrorNumber
,ERROR_SEVERITY() AS ErrorSeverity
,ERROR_STATE() AS ErrorState
,ERROR_PROCEDURE() AS ErrorProcedure
,ERROR_LINE() AS ErrorLine
,ERROR_MESSAGE() AS ErrorMessage;

IF @@TRANCOUNT > 0
ROLLBACK TRANSACTION;

END CATCH;

IF @@TRANCOUNT > 0
COMMIT TRANSACTION;
END;

You might also like