how to convert the following udf function into a stored procedure?

Hi Experts,
Can someone help me convert the following function into a stored procedure?

CREATE FUNCTION [dbo].[fnOrientLastNoteID]
(
	@Orientationid	AS	int
)
RETURNS int
AS
BEGIN
	DECLARE @Result AS int 

	select @Result =   MAX(ID) 
FROM         dbo.OrientationNotes
where OrientationID = @OrientationID;
--GROUP BY OrientationID  -- you don't need to group
	RETURN @Result;
END

GO

Open in new window

Thanks
LVL 6
bfuchsAsked:
Who is Participating?

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

x
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.

Mark ElySenior Coldfusion DeveloperCommented:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE sp_OrientLastNoteID
	
	@OrientationID int
AS
BEGIN
	
	SET NOCOUNT ON;

   select MAX(ID) AS MaxID 
FROM     dbo.OrientationNotes
where OrientationID = @OrientationID;

END
GO

Open in new window

0

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
Scott PletcherSenior DBACommented:
CREATE PROCEDURE [dbo].[procOrientLastNoteID]
(
      @Orientationid      AS      int
)
AS
SET NOCOUNT ON;

SELECT MAX(ID)
FROM      dbo.OrientationNotes
WHERE OrientationID = @OrientationID

GO
0
Scott PletcherSenior DBACommented:
DOH, just saw someone had already posted the code.  Btw, the original function can be made slightly more efficient by getting rid of the local variable:

CREATE FUNCTION [dbo].[fnOrientLastNoteID]
(
      @Orientationid      AS      int
)
RETURNS int
AS
BEGIN
RETURN (
    SELECT MAX(ID)
    FROM         dbo.OrientationNotes
    WHERE OrientationID = @OrientationID
)
END
GO
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

bfuchsAuthor Commented:
Thanks you guys,
Perhaps you may as well know how can I get that to work in my Access App form?

See following.
http://www.experts-exchange.com/Database/MS_Access/Q_28659574.html#a40735042
0
Mark ElySenior Coldfusion DeveloperCommented:
No worries... however just curious why did you choose ScottPletcher answer over mine.. Our answers were identical and I posted first?
0
bfuchsAuthor Commented:
Sorry, I meant to assign 400 for your answer
Already requested attention on this matter.
0
bfuchsAuthor Commented:
Corrected, Apologize for that..
0
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
Microsoft Access

From novice to tech pro — start learning today.