By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,543 Members | 1,887 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,543 IT Pros & Developers. It's quick & easy.

I want to update the column in a table based on the updation of theother column in the same table

P: n/a
Hi ,

I want to update the column in a table based on the updation of the
other column in the same table, but not getting the desired result.
DDL:

CREATE TABLE [dbo].[TestTable](
[Col1] [int] NULL,
[Col2] [int] NULL,
[Col3] [int] NULL
) ON [PRIMARY]

Insert into (Col1, Col2, Col3) Values(1 , 1, 1)

Desired Result
Col1 = 2
Col2 = 3
Col3 = 4
This is the query that I'm using

update TestTable
set Col1= Col1 + 1,
Col2 = Col1 + 1,
Col3 = Col2 + 1
but the result I get is
Col1 = 2
Col2 = 2
Col3 = 2
Thanks for your help in advance.

Jun 27 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
(ab*************@gmail.com) writes:
I want to update the column in a table based on the updation of the
other column in the same table, but not getting the desired result.
DDL:

CREATE TABLE [dbo].[TestTable](
[Col1] [int] NULL,
[Col2] [int] NULL,
[Col3] [int] NULL
) ON [PRIMARY]

Insert into (Col1, Col2, Col3) Values(1 , 1, 1)

Desired Result
Col1 = 2
Col2 = 3
Col3 = 4
This is the query that I'm using

update TestTable
set Col1= Col1 + 1,
Col2 = Col1 + 1,
Col3 = Col2 + 1
Try

update TestTable
set Col1 = Col1 + 1,
Col2 = Col1 + 2,
Col3 = Col2 + 3

All columns in the SET clause are computed and set in parallel. It's not
that first is the first column listed computed and set, then the next one
and so on.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.