If I run a query like this:
insert into table (unique_id, column)
select
(isnull(max(cast(unique_id as int)), 1) + 1 from table) as id,
another_column
from another_table
the unique_id field always comes out as 1 and doesn’t increment. Is there a way to have this increment whilst doing the insert?
p.s This is a simple version of what I am doing but the example is accurate
Edit: SQL Server 2008
Thanks
use identity(mssql), auto_increment(mysql) or sequences (psql/oracle/any other proper DB).