473,654 Members | 3,042 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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
1 2766
(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****@sommarsk og.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
10436
by: Mark A Framness | last post by:
Greetings, I am working on a project and we need to write a conversion script to initialize a new field on a table. The number of records on this table is on the order of millions so routine selection and update takes a long time. I am tasked with writing a pl/sql proc that utilizes array processing to update the column.
7
248458
by: Dave | last post by:
I have 2 tables, one with names, and another with addresses, joined by their CIVICID number (unique to the ADDRESSINFO table) in Oracle. I need to update a field in the NAMEINFO table for a particular surname in a particular town. I can select the records fine with this syntax (testing in Oracle SQL* Plus) SELECT NAMEINFO.LASTNAME, NAMEINFO.FIRSTNAME, NAMEINFO.MIDDLENAME, NAMEINFO.GENDER, ADDRESSINFO.REGION FROM NAMEINFO, ADDRESSINFO...
8
89304
by: Lauren Quantrell | last post by:
In VBA, I constructed the following to update all records in tblmyTable with each records in tblmyTableTEMP having the same UniqueID: UPDATE tblMyTable RIGHT JOIN tblMyTableTEMP ON tblMyTable.UniqueID = tblMyTableTEMP.UniqueID SET tblMyTable.myField = tblMyTableTEMP.myField, tblMyTable.myField2 = tblMyTableTEMP.myField2,
17
5005
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by cust_no, ded_type_cd, chk_no)
0
1788
by: Manish | last post by:
Hey Guys I am using a datagrid to extract information out of SQL Server datbase. The fields extracted are category,week,budget,Last Year,Forecast and Projection. Also i add a calculated column Week% to the datatable. Also i add calculated row - SPLH(Revenue/Hours) and AWR(Payroll/Hours) for each week. My grid layout is as follows- Catgory Week Budget LY Fcst Projection Week% Revenue 1 2000 1500 2400 2000 Cost ...
1
6470
by: Sharon | last post by:
Hello All, Is it possible to update Sql Table through DataGrid. I have a DataGrid which is being populated through a stored procedure, all i wanted to do is to update one field (FieldName-Authorised) which has a datatype bit through DataGrid but not sure how to go about it. Any Ideas Guys on this one, your help is greatly appreciated. This is the procedure used to populate the datagrid, The primary key for the table is EntryID which...
4
8791
by: mmanojkumar | last post by:
Sir, I have a recordset "ADODC_path.recordset" which takes input from two tables When the field values are put into the textboxes and then edited and updated back into the tables, using the following codes, everything works fine. "select * from path,Station where path.StationCode=Station.StationCode and path.traincode=" & Text2.Text Two tables Station(fields: StationCode and StationName) and Path(fields: StationCode ,TrainCode...
0
3533
by: ceevee | last post by:
Hi Everyone, Was hoping you could help me understand what I may be doing wrong. I am trying to update a column of one table from the data in a column of another table. Here are my create statements: CREATE TABLE dictethnicity(sbirthplace char(15) not null, bplacedesc varchar(100) not null, usstateflag int, ethgrpcode char(5)); CREATE TABLE voterethnicity(id bigint, sbirthplace char(15), bplacedesc varchar(100), usstateflag int,...
3
7556
by: tennytitansgeek | last post by:
I am working on an update trigger that updates certain columns in table two when table one is updated. Example If Column a, b, or c is updated in table 1, I need those to be updated in table 2- Column a, b, or c based on the unique identifier column (let's say column a in both tables are the ids). The other problem I have is that for both table there is also a colum D. In Table 1 column d can be = red, blue, or pink. If column d is = red or...
0
8290
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8815
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8482
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7306
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6161
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5622
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1916
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1593
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.