Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 inserting records

Author  Topic 

sent_sara
Constraint Violating Yak Guru

377 Posts

Posted - 2007-02-23 : 03:50:43
Hi fys,

Iam having a empty table as shown below,where idno is a primary key of integer type,name is a varchar
gworker
------
idno name

in another table,oworker i have 5 records(name) as shown below:
oworker
--------
name

senthil
sasi
latha
armu
ammu

just i want to insert into gworker from oworker table how to do this?

so what like this:
insert into gworker(idno,name) values select max(gworker.idno)+1,name from oworker

the above statement is not working fine:
just i need to increment value in gworker by one how to do this??????

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-02-23 : 03:57:24
is idno an identity column ?

insert into gworker (name)
select name from oworker



KH

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-02-23 : 04:04:23
if column idno allows null value

insert gworker(name)
select name from oworker

declare @idno int
select @idno = 0

update u
set idno = @idno,
@idno = @idno + 1
from gworker u



KH

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-02-23 : 04:25:24
or if the name in table oworker is unique

insert into gworker(idno, name)
select idno = (select count(*) from oworker x where x.name <= o.name),
name
from oworker o
order by name



KH

Go to Top of Page
   

- Advertisement -