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
 Transact-SQL (2000)
 moving data across tables

Author  Topic 

mike123
Master Smack Fu Yak Hacker

1462 Posts

Posted - 2002-05-16 : 13:44:28

I'm trying to modify my existing database design here. What I need to do is move all the data from FORUM_MEMBERS.M_LEVEL into TBLUSERDETAILS.FORUM_LEVEL. tbluserdetails has a field NAMEONLINE that corresponds with FORUM_MEMBERS M_NAME. How Can I do this? I'm not sure where to go with what I have below so far.


insert into tblUserDetails(Forum_Level) select M_Level FROM FORUM_MEMBERS


Thanks a bunch

joldham
Wiseass Yak Posting Master

300 Posts

Posted - 2002-05-16 : 13:54:21
Can you show us your table structures with all the columns you want moved?

My best guess is:

INSERT INTO tblUserDetail (Forum_Level, NAMENSONLINE)
SELECT M_Level, M_NAME
FROM FORUM_MEMBERS

Jeremy

Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-05-16 : 16:21:06
..just a guess....do you want to insert where not exists and update where exists?



insert tbluserdetails(forum_level)
select
m_level
from
forum_members f
where
not exists (
select 1
from
tbluserdetails
where
nameonline = f.m_name)

update
tbluserdetails
set
forum_level = f.m_level
from
tbluserdetails u
inner join forum_members f
on u.nameonline = f.m_name

 


<O>
Go to Top of Page

mike123
Master Smack Fu Yak Hacker

1462 Posts

Posted - 2002-05-16 : 17:35:46

Thanks,

The two tables are both the same structure. As such

TBLUSERDETAILS ////////// FORUM_MEMBERS

NAMEONLINE ////////// M_NAME
FORUM_LEVEL ////////// M_LEVEL



All the users names in forum members(M_NAME) exist in tbluserdetails(NAMEONLINE) (they should anyways so unless there are integrity errors, altho I checked and there doesnt seem to be any). I want to get all the corresponding LEVELS over from one table to the other.

Thanks, I hope that clears it up






Edited by - mike123 on 05/16/2002 17:36:38
Go to Top of Page
   

- Advertisement -