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.
| 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 varchargworker------idno namein another table,oworker i have 5 records(name) as shown below:oworker --------namesenthilsasilathaarmuammujust 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 oworkerthe 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 |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-02-23 : 04:04:23
|
if column idno allows null valueinsert gworker(name)select name from oworkerdeclare @idno intselect @idno = 0update uset idno = @idno, @idno = @idno + 1from gworker u KH |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-02-23 : 04:25:24
|
or if the name in table oworker is uniqueinsert into gworker(idno, name)select idno = (select count(*) from oworker x where x.name <= o.name), namefrom oworker oorder by name KH |
 |
|
|
|
|
|
|
|