I have 1 stored procedure that returns a Datetime value , I want to convert it into function so that i can call this function in multiple stored procedure? How can we do that?
Loading
I have 1 stored procedure that returns a Datetime value , I want to convert it into function so that i can call this function in multiple stored procedure? How can we do that?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Naimish MakwanaPosted Mar 3, 2023, 10:51 AM
Hello Basit,
You can create function like below.
Thanks
Naimish Makwana
Basit NisarPosted Mar 6, 2023, 4:55 PM
Thanks very much fr help
Tuhin PaulPosted Mar 3, 2023, 10:52 AM
Hello Basit,
To convert your stored procedure that returns a datetime value into a function that can be called from multiple stored procedures, you can follow these steps:
1. Create a new function with the same name as your stored procedure and with the appropriate return type. like:
2. Now you should copy the body of your stored procedure into the body of your new function, making sure to remove any parameters that are no longer needed.
3. Replace any SELECT statements in the stored procedure with RETURN statements in the function. See below, lets assume your stored procedure looks like this:
You would convert it to a function :
4. Modify your existing stored procedures to call the new function instead of the old stored procedure, passing any required parameters. like below:
With these changes, you should be able to call your new function from multiple stored procedures, passing in any required parameters, and returning a datetime value.
Amit MohantyPosted Mar 3, 2023, 10:50 AM
Rewrite the stored procedure as a function, using the CREATE FUNCTION statement. The syntax of the CREATE FUNCTION statement is different from that of the CREATE PROCEDURE statement, so you will need to modify the code accordingly.
Example: