Insert query into SQL function

Can I write an insert request inside a function on SQL 2008 server. If I try, I get an error Invalid side effect of the INSERT statement inside the function. Please help me. But I want it to be a function, not a stored procedure

Create function EFT_DL_FUNC_AUDTI_BATCH_START (@i_db_name varchar(20))
returns int as
begin
    insert into table_name(db_name) values (@i_db_name)
    return 0
end
+3
source share
1 answer

Quote from here :

User-defined functions cannot be used to modify base table information. The DML INSERT, UPDATE, and DELETE statements cannot be used in base tables.

Thus, you cannot do INSERT in a function.

You might want to explain why you do not want to use the procedure.

+14
source

Source: https://habr.com/ru/post/1794066/


All Articles