tsql - SQL Server Stored Procedure to dump oldest X records when new records added -


i have licensing scenario when person activates new system adds old activations lockout table can have latest x systems activated. need pass parameter of how many recent activations keep , older activations should added lockout table if not locked out. i'm not sure how best this, i.e. temp table (which i've never done) etc.

for example, activation comes in john doe on system xyz. need query activations table activations john doe , sort date desc. john doe may have license allowing 2 systems in case need records older top 2 deactivated, i.e. inserted lockouts table.

thanks in advance assistance.

something perhaps?

insert lockouts     (<column list>)     select <column list>         (select <column list>,                       row_number() on (order date desc) rownum                   activations) t         t.rownum > @numlicenses 

Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -