10hero
10hero

Reputation: 15

Update one row only out of two identical rows in sybase

I have three rows in the database out of those two are identical. Out of those two same rows I have to make changes in one using the sybase.Ex.

Row1: ABC 456 ancient block
Row2: ABC 456 ancient block
Row3: DEF 678 class   block

I have to make changes in one of the first two block by changing ABC to XYZ.If there are only two identical blocks then I am doing the below method.

begin transaction AA
set rowcount 1
update table 
set col1 = XYZ
where col1 = ABC
commit transaction AA
set rowcount 0

It is easy if there are two identical rows but if two identical and one different then sybase picks the unique row and updates it. Can someone tell how to solve this three rows problem ? I am using aseisql for the Sybase.

Upvotes: 0

Views: 2427

Answers (2)

10hero
10hero

Reputation: 15

This is the solution I figured.

begin transaction a
set rowcount 2
update table 
set col1 = XYZ
where col4 = block

commit transaction a
set rowcount 0

It will update one of the duplicate rows and the unique row. Then I will update the unique row to its original value separately using the update statement. I know its sound crude but no one has answered satisfactorily.

Upvotes: 0

Michał Szkudlarek
Michał Szkudlarek

Reputation: 1502

Have you tried:

update top 1 table 
set col1 = XYZ
where col1 = ABC

Upvotes: 1

Related Questions