How to get the next number in a sequence

前端 未结 9 1068
死守一世寂寞
死守一世寂寞 2020-12-04 01:48

I have a table like this:

+----+-----------+------+-------+--+
| id | Part      | Seq  | Model |  |
+----+-----------+------+-------+--+
| 1  | Head      | 0         


        
9条回答
  •  死守一世寂寞
    2020-12-04 02:00

    create function dbo.fncalnxt(@model int)
    returns int 
    begin
    declare @seq int
    select @seq= case when @model=3 then max(id) --else
    end from tblBodyParts
    return @seq+1
    end
    --query idea To insert values, ideal if using SP to insert
    insert into tblBodyParts values('groin',dbo.fncalnxt(@model),@model)
    

    You can try this i guess. A novice shot, correct me if im wrong. i'd suggest using function to get the value in seq column based on model; you'll have to check the else case though to return another value you want, when model!=3, it'll return null now.

提交回复
热议问题