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
 Old Forums
 CLOSED - General SQL Server
 update query

Author  Topic 

mateenmohd
Constraint Violating Yak Guru

297 Posts

Posted - 2004-08-24 : 03:21:47
update (insert) data from one table to another table.

employees table
------------------
empno joindate
1234
1235
1236
.......


info table
------------------
empno joindate
1234 3/11/2003
1235 6/10/2002
1236 9/12/2000
.....



how can update (insert) the employees table column joindate with the info table column joindate ?
I want to insert (update) info table joindate into employees table.
insert all joindate into employees joindate where employees.empno=info.empno

update employees
set joindate =
from info
where employees.empno=info.empno
and joindate is null

regards.

Mateen


spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-08-24 : 04:28:26
this should do the update:

update e
set e.joinDate = i.joinDate
from employees e
inner join info i on (e.empno = i.empno)


Go with the flow & have fun! Else fight the flow :)
Go to Top of Page

mateenmohd
Constraint Violating Yak Guru

297 Posts

Posted - 2004-08-25 : 06:24:10
thanks for response.

it doble the records.
I have four hundred records, after run this query
it show eight hundred records why ?

Mateen
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-08-25 : 06:38:40
well, with out more info there's not really much to say.
post the create table, insert into (sample data), and desired results so we can test it on our machines and give the answer.

Go with the flow & have fun! Else fight the flow :)
Go to Top of Page
   

- Advertisement -