rcowen00
asked on
Max Function
I am trying to build a Function that returns the PlacerUserKey that is associated with the most recent record in a table. How do I go about returning the User record that has the most recent Created date? The function below does not work. Thank you.
CREATE FUNCTION dbo.GetCurrentPlacer
(
@OrderKey
)
RETURNS INT
AS
BEGIN
DECLARE @CurrentPlacer VARCHAR
SELECT @CurrentPlacer = (MAX(Created) AS CurrCreated, PlacerUserKey
FROM Placer AS pl
WHERE (OrderKey = @OrderKey)
GROUP BY Created, PlacerUserKey
ORDER BY Created DESC)
RETURN @CurrentPlacer
END
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.