I have a table with two primary key fileds. I will be running a process to populate the data into the table.For each process the first field is constant and second field is auto increment one.
My statements are insert into select ** from ** type one.
How do I auto increment second filed per run. Any delivered function available or any suggestion Pl.............It would help us answer you question a lot faster if you supplied DDL, sample Data, and the expected result...|||DDL:
Table1-
id: PK
lin_nbr: PK
filed1
field2
Table2-
filed1
filed2
filed3
Data:
insert into table1 (id, lin_nbr, filed1, filed2) (select 'a001', auto incr , field1,filed2 from table2 )
Result in table2 should be
a001 1 abc def
a001 2 ghi jkl
a001 3 xyz gfg|||Make your lin_nbr an identity column and when you insert, insert all but the lin_nbr column. SQL Server will auto-increment that column for you!
Table1-
id_col int not null,
lin_nbr int identity not null,
filed1 varchar(52) null, -- (or not null, whichever suits your purposes)
field2 varchar(52) null -- (same applies)|||I want that increament is based on the another pk. pl have a look at the data below
a001 1 abc def
a001 2 ghi jkl
a001 3 xyz gfg
a002 1 abc def
a002 2 ghi jkl
a002 3 xyz gfg
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment