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 2005 Forums
 Transact-SQL (2005)
 update mutliple columns in table

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2010-11-29 : 03:58:41
i want to run the following

update mytable (field1,field2,field3,field4)
select field1,feild2,field3,field4 from mytable2 where update=1


what's the best way to do this?
it's a big table - do i have to set a join and do each field separately?

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2010-11-29 : 04:08:15
[code]UPDATE a SET
a.Column1 = b.Column1,
a.Column2 = b.Column2,
FROM table1 a
INNER JOIN table2 b
ON a.ID= b.ID
WHERE b.Update = 1[/code]

- Lumbago

My blog (yes, I have a blog now! just not that much content yet)
-> www.thefirstsql.com
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2010-11-29 : 05:19:32
Cannot resolve the collation conflict between "Latin1_General_CI_AS" and "SQL_Latin1_General_CP1_CI_AS" in the equal to operation.


for some reason when i run an insert i don't get this problem
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2010-11-29 : 05:36:08
[code]UPDATE a SET
a.Column1 = b.Column1 COLLATE SQL_Latin1_General_CP1_CI_AS,
a.Column2 = b.Column2 COLLATE SQL_Latin1_General_CP1_CI_AS,
FROM table1 a
INNER JOIN table2 b
ON a.ID= b.ID
WHERE b.Update = 1[/code]

- Lumbago

My blog (yes, I have a blog now! just not that much content yet)
-> www.thefirstsql.com
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2010-11-29 : 06:46:07
thanks:)
Go to Top of Page
   

- Advertisement -