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
 How to insert or update increment of 2 ?

Author  Topic 

Vaishu
Posting Yak Master

178 Posts

Posted - 2008-01-21 : 17:36:51
HI

I have table with 20 columns. One of the column(col1) in the table has value like below

Col1 -----------Col2
123------------- 2
123--------------4
123--------------6
453--------------2
898--------------2
723--------------2
723--------------4

How to do insert or update increment of 2 in a column (col2) for every same value in the Col1?

I am using Access. Is it possible to with the query ?

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-01-21 : 17:57:49
quote:
Originally posted by Vaishu

HI

I have table with 20 columns. One of the column(col1) in the table has value like below

Col1 -----------Col2
123------------- 2
123--------------4
123--------------6
453--------------2
898--------------2
723--------------2
723--------------4

How to do insert or update increment of 2 in a column (col2) for every same value in the Col1?

I am using Access. Is it possible to with the query ?



If you are looking for a solution for MS Access, there is a sererate forum for that. This forum is for MS Sql Server.

Be One with the Optimizer
TG
Go to Top of Page

sundaram_r_1984
Starting Member

11 Posts

Posted - 2008-01-22 : 01:56:52
IT WILL WORK IF YOU ARE USING ASP & MSACCESS.. ONLY FOR ADDING NEW RECORD
col1 = 123
rs.open "select top 1 * from <tablename> where col1 = 123 order by col2 desc",con,2,3
if not rs.eof then
previousValue = rs("col2") + 2
else
previousValue = 0
end if
rs.close

rs.open "SELECT * FROM <tablename>",con,2,3
rs.addnew
rs("col1") = 123
rs("col2") = previousValue
rs.update
rs.close
Go to Top of Page
   

- Advertisement -