I am creating a simple function which inserts a row to a table. After the insertion I don't need the function to return anything. I just checked the function creation syntax in MSDN and it seems like a function must return a value. I also tried to create a function but got syntax error.
I wonder if there is a way to create a function which doesn't return any value.
Can anyone please let me know if there is a way to create such a function? Thanks in advance:)
Functions can return VOID if there is no useful data to return, as in a SQL DELETE , INSERT , or UPDATE statement.
You are never inserting anything into the table variable you're returning. What is supposed to happen? You are also calling the procedure with int and varchar, rather than the other way around.
The RETURN statement is used to unconditionally and immediately end an SQL procedure by returning the flow of control to the caller of the stored procedure. When the RETURN statement runs, it must return an integer value. If the return value is not provided, the default is 0.
How to Create a Function Without a Parameter in SQL. Line one creates a function then named the function “YTDSALES()”. You can give your function any name. Remember to add parenthesis to the name of the function when without a parameter.
Then use Stored Procedure to achieve your requirement. Because function is meant for returning values.
create stored procedure instead of function
Create proc my_proc()
as
BEGIN
<your insert statement >
END
See Examples here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With