Después de la primera reunión hemos hecho algunos avances, ya tenemos una cuenta de azure en la cual tenemos ya la base de datos corriendo, ya se han hecho algunos Stored Procedure, a su ves se han realizado algunas funciones que hacen mas simple los SP.
Se han hecho pequeñas modificaciones al modelo fisico de la base de datos:
INICIAL:
Algunos de los Stored Procedure realizados:
El siguiente Stored Procedure realiza las descalificaciones si el corredor tiene mas de 30 puntos de castigo:
CREATE PROCEDURE [dbo].[SP_Disqualify]
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
UPDATE RunnersXChallenge
SET FK_Status = 1
WHERE AcumPunishPts > 30
END
GO
El siguiente Stored procedure procesa los resultados de las carreras y campeonatos:
CREATE PROCEDURE [dbo].[SP_ResultProcessing]
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
BEGIN TRANSACTION
UPDATE dbo.RunnersXChallenge SET AcumPoints = dbo.FN_AcumPts(ID);
UPDATE dbo.RunnersXChallenge SET AcumTime = dbo.FN_AcumTimeByPosition(ID);
COMMIT
END
GO
Se han hecho pequeñas modificaciones al modelo fisico de la base de datos:
INICIAL:
DEFINITIVA:
Algunas de las funciones realizadas son:
Función para acumular los puntos obtenidos del corredor:
Create FUNCTION FN_AcumPts
(
-- Add the parameters for the function here
@RunnerXChallenge int
)
RETURNS int
AS
BEGIN
-- Declare the return variable here
DECLARE @AcumulatedPoints INT
-- Add the T-SQL statements to compute the return value here
SELECT @AcumulatedPoints = SUM(Amount)
FROM PointsMovement
WHERE PointsMovement.FK_RunnersXChallenge = @RunnerXChallenge
-- Return the result of the function
RETURN @AcumulatedPoints
END
GO
Función para acumular los puntos de castigo del corredor:
alter FUNCTION FN_AcumPunishPts
(
-- Add the parameters for the function here
@RunnerXChallenge int
)
RETURNS int
AS
BEGIN
-- Declare the return variable here
DECLARE @AcumulatedPoints INT
-- Add the T-SQL statements to compute the return value here
SELECT @AcumulatedPoints = SUM(Amount)
FROM PunishPtsMovement
WHERE PunishPtsMovement.FK_RunnersXChallenge = @RunnerXChallenge
-- Return the result of the function
RETURN @AcumulatedPoints
END
GO
Función para determinar la posicion dependiendo del tiempo:
ALTER FUNCTION FN_AcumTimeByPosition
(
-- Add the parameters for the function here
@RunnerXChallenge int
)
RETURNS time(7)
AS
BEGIN
DECLARE @RunnersXChallengeByPositions TABLE
(
ID int NOT NULL,
Number varchar(50) NOT NULL,
AcumTime time(7) NOT NULL,
AcumPoints int NOT NULL,
AcumPunishPts int NOT NULL,
ET_Time time(7) NOT NULL,
FK_Runners int NOT NULL
)
INSERT INTO @RunnersXChallengeByPositions(ID,Number,AcumTime,AcumPoints,AcumPunishPts,ET_Time,FK_Runners)
SELECT R.ID,R.Number,R.AcumTime,R.AcumPoints,R.AcumPunishPts,P.ET_Time,P.FK_Runners
FROM RunnersXChallenge R INNER JOIN Positions P ON R.FK_Runners = P.FK_Runners
WHERE R.ID = @RunnerXChallenge
UPDATE R
SET R.AcumTime = (RC.Acumtime + R.AcumTime)
FROM RunnersXChallenge R INNER JOIN @RunnersXChallengeByPositions RC
ON R.ID = RC.ID;
-- Declare the return variable here
DECLARE @AcumulatedTime time(7)
-- Add the T-SQL statements to compute the return value here
-- SELECT @AcumulatedTime = TimeAcum FROM
-- Return the result of the function
RETURN @AcumulatedTime
END
GO
El siguiente Stored Procedure realiza las descalificaciones si el corredor tiene mas de 30 puntos de castigo:
CREATE PROCEDURE [dbo].[SP_Disqualify]
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
UPDATE RunnersXChallenge
SET FK_Status = 1
WHERE AcumPunishPts > 30
END
GO
El siguiente Stored procedure procesa los resultados de las carreras y campeonatos:
CREATE PROCEDURE [dbo].[SP_ResultProcessing]
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
BEGIN TRANSACTION
UPDATE dbo.RunnersXChallenge SET AcumPoints = dbo.FN_AcumPts(ID);
UPDATE dbo.RunnersXChallenge SET AcumTime = dbo.FN_AcumTimeByPosition(ID);
COMMIT
END
GO
Por la implementacion de estas funciones y Stored Procedure son 3 horas las cuales fueron distribuidas en 1 hora por día.

No hay comentarios:
Publicar un comentario