Bonjour,

est il possible de placer une variable comme n° de départ pour Identity ?

Voici comment je m'y prends (mal ?) car il me met "Incorrect syntax near '@maxnrid'." au niveau d'Identity

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
DECLARE @maxnrid decimal(15,0)
 
	select @maxnrid = max(nrid) from table1
    if @maxnrid is null 
        BEGIN
            set @maxnrid = 0 
        END
	set @maxnrid = @maxnrid + 1
 
-- jusqu'ici tout va bien, je récupère ma valeur, puis j'ajoute mon champ dans une table temporaire avec ma variable comme valeur de départ :
 
alter table #tmp0
add po0_nrid decimal(15,0) identity(@maxnrid,1);