Código SQL:
Ver originalCREATE FUNCTION DBO.M4FN_MAX_PLAZA (@pID_EMPLEADO VARCHAR, @pFEC_PAGO DATETIME)
RETURNS NUMERIC
AS
BEGIN
DECLARE @vMAX_PLAZA NUMERIC (10)
DECLARE @MYVAR INT -- No se de que tipo deba ser esta variable
-- Obtengo el valor maximo
SELECT @MYVAR = MAX(RLA.FEC_IMPUTACION)
FROM M4_ACUMULADO_RL RLA INNER JOIN M4_ACUMULADO_RL RL1
ON RLA.ID_EMPLEADO = RL1.ID_EMPLEADO
AND RLA.FEC_PAGO = RL1.FEC_PAGO
RETURN(
SELECT DISTINCT (RL.ID_PLAZA)
FROM M4T_ACUMULADO_RL RL
INNER JOIN M4T_ACUMULADO_RL1 RL1
ON RL.ID_SOCIEDAD = RL1.ID_SOCIEDAD
AND RL.ID_EMPLEADO = RL1.ID_EMPLEADO
AND RL.FEC_ALTA_EMPLEADO = RL1.FEC_ALTA_EMPLEADO
AND RL.FEC_IMPUTACION = RL1.FEC_IMPUTACION
AND RL.FEC_PAGO = RL1.FEC_PAGO
INNER JOIN M4T_LISTADO_NOM LN
ON RL.ID_SOCIEDAD = LN.ID_SOCIEDAD
AND RL.ID_EMPLEADO = LN.ID_EMPLEADO
AND RL.FEC_ALTA_EMPLEADO = LN.FEC_ALTA_EMPLEADO
AND RL.FEC_IMPUTACION = LN.FEC_IMPUTACION
AND RL.FEC_PAGO = LN.FEC_PAGO
WHERE (RL.FEC_IMPUTACION) = @MYVAR
AND RL.ID_EMPLEADO = @pID_EMPLEADO
AND RL.FEC_PAGO = @pFEC_PAGO)
END