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
 General SQL Server Forums
 New to SQL Server Programming
 Merging tables

Author  Topic 

brunstrom
Starting Member

3 Posts

Posted - 2008-10-16 : 10:46:26
New here, new to SQL - please be gentle with me

I have two tables -
Deaths - Year,Weekno,NoOfDeaths
Births - Year,Weekno,NoOf Births

Assuming I add a 'NoofDeaths' to my 'births' table, how can I populate it with the corresponding data from the Deaths table ?

thanks in advance

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-10-16 : 10:51:57
insert into Births(OtherColumns, NoofDeaths)
select OtherColumns, 1 -- or other value depending on what this column represents
from deaths,

_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.1 out!
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2008-10-16 : 10:53:10
update b
set NoOfDeaths=d.NoOfdeaths
from Births as b
join Deaths as d on (d.Year=b.Year and d.Weekno=b.Weekno)

Planning replaces chance by mistake
Go to Top of Page

brunstrom
Starting Member

3 Posts

Posted - 2008-10-16 : 12:15:53
quote:
Originally posted by webfred

update b
set NoOfDeaths=d.NoOfdeaths
from Births as b
join Deaths as d on (d.Year=b.Year and d.Weekno=b.Weekno)

Planning replaces chance by mistake



looks like what I would have expexcted, so -

update b
set countgo=tdeaths.countgo
from tbirths as b
join tdeaths as d on (d.yearno=b.yearno and d.weekno=b.weekno)

BUT

The multi-part identifier "tdeaths.countgo" could not be bound.

que ?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-16 : 12:29:04
quote:
Originally posted by brunstrom

quote:
Originally posted by webfred

update b
set NoOfDeaths=d.NoOfdeaths
from Births as b
join Deaths as d on (d.Year=b.Year and d.Weekno=b.Weekno)

Planning replaces chance by mistake



looks like what I would have expexcted, so -

update b
set countgo=tdeathsd.countgo
from tbirths as b
join tdeaths as d on (d.yearno=b.yearno and d.weekno=b.weekno)

BUT

The multi-part identifier "tdeaths.countgo" could not be bound.

que ?


modify like above
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-10-17 : 03:46:37
quote:
Originally posted by brunstrom

quote:
Originally posted by webfred

update b
set NoOfDeaths=d.NoOfdeaths
from Births as b
join Deaths as d on (d.Year=b.Year and d.Weekno=b.Weekno)

Planning replaces chance by mistake



looks like what I would have expexcted, so -

update b
set countgo=tdeaths.countgo
from tbirths as b
join tdeaths as d on (d.yearno=b.yearno and d.weekno=b.weekno)

BUT

The multi-part identifier "tdeaths.countgo" could not be bound.

que ?


Why did you modify the suggested query?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

brunstrom
Starting Member

3 Posts

Posted - 2008-10-17 : 08:41:08
quote:
Originally posted by visakh16

quote:
Originally posted by brunstrom

quote:
Originally posted by webfred

update b
set NoOfDeaths=d.NoOfdeaths
from Births as b
join Deaths as d on (d.Year=b.Year and d.Weekno=b.Weekno)

Planning replaces chance by mistake



looks like what I would have expexcted, so -

update b
set countgo=tdeathsd.countgo
from tbirths as b
join tdeaths as d on (d.yearno=b.yearno and d.weekno=b.weekno)

BUT

The multi-part identifier "tdeaths.countgo" could not be bound.

que ?


modify like above



yeaaaa
Go to Top of Page
   

- Advertisement -