hi
i m try write a function in sql server there is a error but not under stand. error is
Msg 443, Level 16, State 15, Procedure get_advice_no, Line 21
Invalid use of a side-effecting operator 'UPDATE' within a function.
Msg 443, Level 16, State 15, Procedure get_advice_no, Line 34
Invalid use of a side-effecting operator 'INSERT' within a function.
my function code is
- ALTER FUNCTION [dbo].[get_advice_no](@vcounter_type nvarchar(5) )
- RETURNS int
- AS
- BEGIN
-
- DECLARE @vadvice_no int;
-
- select @vadvice_no = (SELECT (isnull(CONSTANT_NO,0) + 1) FROM CA_CONSTANT
- WHERE CONSTANT_TYPE = @vcounter_type);
- if @vadvice_no > 0
- begin
-
-
- update ca_constant
- set constant_no = @vadvice_no
- where CONSTANT_TYPE = @vcounter_type;
-
- end
- else
- begin
- set @vadvice_no = 1;
- IF (@vcounter_type = 'ADV_2')
- begin
- set @vadvice_no = 75001;
- end
- INSERT INTO CA_CONSTANT(CONSTANT_TYPE,CONSTANT_NO)
- VALUES(@vcounter_type,@vadvice_no);
- end
- RETURN(@vadvice_no);
-
- END
pls tell me what is wrong