fjtello / SQL-C-sharp

Common programming and coding tips and howtos
0 stars 0 forks source link

SQL hints [#sequence #restart #execute #sp_executesql] #33

Open fjtello opened 7 years ago

fjtello commented 7 years ago

DECLARE @max as int; SET @max = (SELECT MAX(idLog) FROM logs); IF(@max is null) SET @max = 0; SET @max = @max + 1;

DECLARE @sqlCommand nvarchar(1000) SET @sqlCommand = 'alter sequence seq_logs restart with ' + CONVERT(VARCHAR(16), @max) + ';';

EXECUTE sp_executesql @sqlCommand;