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
 Need some help with copying data

Author  Topic 

kristapsb
Starting Member

4 Posts

Posted - 2010-01-28 : 15:58:06
Hello,

I`m new to SQL. I have learned some basics, but now I need help from smarter people.

In database I have two tables - MEMB_CREDITS and MEMB_INFO. In MEMB_CREDITS are two columns - memb__id and credits, in MEMB_INFO I have same two and some other colums. All I need is to copy data from MEMB_CREDITS to MEMB_INFO. It`s like in both tables, users with the same memb__id need to have the same amount of credits. Can anyone help me please? Maybe there is some way to create a script, that automaticly do all these things?

Server - MSSQL 2000

Kristapsb

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-01-28 : 15:59:53
What about the other 2 columns in the destination table? What should that be valued with and how?
Go to Top of Page

kristapsb
Starting Member

4 Posts

Posted - 2010-01-28 : 16:04:24
It`s like:

Select credits ( column )
From MEMB_CREDITS ( table )
Insert into MEMB_INFO ( table )
Where memb__id=memb__id ( columns )


Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-01-28 : 16:07:35
OK..looks like you need an UPDATE..Try this..
update a
set a.credits = b.credits
from MEMB_INFO a
inner join MEMB_CREDITS b on a.memb__id = b.memb__id



Go to Top of Page

kristapsb
Starting Member

4 Posts

Posted - 2010-01-28 : 16:13:11
Thanks for help! It gives me an error - "Cannot resolve collation conflict for equal to operation."
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-01-28 : 16:19:01
You have different collations for the field in both the tables..
Try this
http://blog.sqlauthority.com/2007/06/11/sql-server-cannot-resolve-collation-conflict-for-equal-to-operation/
Go to Top of Page

kristapsb
Starting Member

4 Posts

Posted - 2010-01-28 : 17:15:33
Thanks, fixed collocation problem and everything works perfectly!
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-01-29 : 09:56:35
You're welcome.
Go to Top of Page
   

- Advertisement -