﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / SQL Server Newbies  / Update multiple columns in multiple rows / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Wed, 19 Jun 2013 07:02:41 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Update multiple columns in multiple rows</title><link>http://www.sqlservercentral.com/Forums/Topic1428500-1292-1.aspx</link><description>David,Thanks very much.[code]DECLARE @Col2 decimal,@Col3 int,@Col4 intSELECT @Col2 = [Col 2],@Col3 = [Col 3],@Col4 = [Col 4]FROM [table]WHERE [Col 1] = 10000 UPDATE [table] SET [Col 2] = @Col2, 	[Col 3] = @Col3, 	[Col 4] = @Col4 WHERE [Col 1] &amp;gt; 10000 [/code]Did exactly what was required.</description><pubDate>Fri, 08 Mar 2013 07:53:47 GMT</pubDate><dc:creator>gj.thorpe</dc:creator></item><item><title>RE: Update multiple columns in multiple rows</title><link>http://www.sqlservercentral.com/Forums/Topic1428500-1292-1.aspx</link><description>[quote][b]ryan.mcatee (3/8/2013)[/b][hr]I think you want something like this?[/quote]or[code="sql"]UPDATE a SET a.[Col 2] = b.[Col 2], 	a.[Col 3] = b.[Col 3], 	a.[Col 4] = b.[Col 4] JOIN [table] b ON b.[Col 1] = 10000 WHERE a.[Col 1] &amp;gt; 10000 [/code]or [code="sql"]DECLARE @Col2 decimal,@Col3 int,@Col4 intSELECT @Col2 = [Col 2],@Col3 = [Col 3],@Col4 = [Col 4]FROM [table]WHERE [Col 1] = 10000 UPDATE [table] SET [Col 2] = @Col2, 	[Col 3] = @Col3, 	[Col 4] = @Col4 WHERE [Col 1] &amp;gt; 10000 [/code]</description><pubDate>Fri, 08 Mar 2013 06:51:23 GMT</pubDate><dc:creator>David Burrows</dc:creator></item><item><title>RE: Update multiple columns in multiple rows</title><link>http://www.sqlservercentral.com/Forums/Topic1428500-1292-1.aspx</link><description>I think you want something like this?[code="sql"]UPDATE {table}SET [Col 2]=(SELECT [Col 2] FROM {table} WHERE [Col 1]=10000)  , [Col 3]=(SELECT [Col 3] FROM {table} WHERE [Col 1]=10000)  , [Col 4]=(SELECT [Col 4] FROM {table} WHERE [Col 1]=10000)[/code]Edit: Misread this.  And I am assuming [Col 1] is unique.</description><pubDate>Fri, 08 Mar 2013 06:03:32 GMT</pubDate><dc:creator>ryan.mcatee</dc:creator></item><item><title>Update multiple columns in multiple rows</title><link>http://www.sqlservercentral.com/Forums/Topic1428500-1292-1.aspx</link><description>I have a table where I need to update multiple columns in each record (multiple rows) to match a single record already in the table.For example:[code]Col 1	Col 2	Col 3	Col 410000	20.00	1	010001	0	0	110002	15.00	1	010003	0	0	0[/code]So, for the above I would like to update values in Col 2, Col 3, Col 4 for records in (10001, 10002, 10003) to match values in Col 2, Col 3, Col 4 where Col 1 = 10000I would like the data to end up like:[code]Col 1	Col 2	Col 3	Col 410000	20.00	1	010001	20.00	1	010002	20.00	1	010003	20.00	1	0[/code]Is it possible to do this in a single statement?</description><pubDate>Fri, 08 Mar 2013 03:54:52 GMT</pubDate><dc:creator>gj.thorpe</dc:creator></item></channel></rss>