Link to home
Start Free TrialLog in
Avatar of rcowen00
rcowen00Flag for United States of America

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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial