create table #test (a int identity(1,1), b varchar(20), c varchar(20))
insert into #test (b,c) values ('bvju','hjab')
insert into #test (b,c) values ('bst','sdfkg')
......
insert into #test (b,c) values ('hdsj','kfsd')
How would I insert the identity value (#test.a
) that got populated from the above insert statements into #sample
table (another table)
create table #sample (d int identity(1,1), e int, f varchar(20))
insert into #sample(e,f) values (identity value from #test table, 'jkhjk')
insert into #sample(e,f) values (identity value from #test table, 'hfhfd')
......
insert into #sample(e,f) values (identity value from #test table, 'khyy')
Could any one please explain how I could implement this for larger set of records (thousands of records)?
Can we use while
loop and scope_identity
? If so, please explain how can we do it?
what would be the scenario if i insert into #test from a select query?
insert into #test (b,c)
select ... from ... (thousands of records)
How would i capture the identity value and use that value into another (#sample)
insert into #sample(e,f)
select (identity value from #test), ... from .... (thousand of records) –
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…