Function Problem

  • Hi All

    my function is

    --drop function priority

    create function priority

    (

    @nRequestDetailsID int

    )

    RETURNS int

    AS

    begin

    declare @pre int, @a int

    select @pre = cnt from counter

    if(@pre>= 4)

    begin

    update counter set cnt = 2

    end

    else

    begin

    update counter set cnt = cnt+1

    end

    RETURN @pre

    end

    but it is not working

    the error is.....................

    Msg 443, Level 16, State 15, Procedure priority, Line 16

    Invalid use of side-effecting or time-dependent operator in 'UPDATE' within a function.

    Msg 443, Level 16, State 15, Procedure priority, Line 20

    Invalid use of side-effecting or time-dependent operator in 'UPDATE' within a function.

    how to slove the problem

    please help meeeeeeeeeeeeee

    yours

    pols

  • Functions are used to return data and cannot (should not... some undocumented workarounds have been suggested) be used to do anything that changes the database state i.e. your UPDATE statement.

    You should be able to do what you want in a stored procedure instead.

    Let us know a bit more about what you are trying to do and one of us should be able to point you in the right direction.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply