Trying to obtain the earlier datetime record between two datetimes

This one has me perplexed

I have a view I built  the following is an example of the results:
I have built an sql function that I want to use to return the ProtocolResponse that is earlier datetime record between two datetimes

so in essence if the @ActionDate is 2018-2-16-18:43:00  I want to return V.Fib/Tach
if @ActionDate  is 2018-02-16 18:55:00 I want to return PEA

for some reason,  I guess I am just stupid I can't figure a way to do do it

here is the function
ALTER FUNCTION [dbo].[ProtocolResponseFind](@ActionDate datetime , @PRID_Unique varchar(30)) 
RETURNS varchar(50)
	 declare @Return Varchar(50);
	 set @Return= (select top 1 ProtocolResponse from  dbo.Criteria_Map_Protocol_Response where ( ????????????) and @PRID_Unique=PRID_Unique
	Return @Return;

Open in new window

Thank you
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott PletcherSenior DBACommented:
ALTER FUNCTION [dbo].[ProtocolResponseFind]
    @ActionDate datetime ,
    @PRID_Unique varchar(30)
RETURNS varchar(50)
        SELECT TOP (1) ProtocolResponse
        FROM dbo.Criteria_Map_Protocol_Response
        WHERE PRID_Unique = @PRID_Unique AND
            ActionDate <= @ActionDate
        ORDER BY ActionDate DESC

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
WillOwnerAuthor Commented:
That worked with a little tweaking.  The sort needed to be on ActionDate.  Thank you for help
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.