cancel
Showing results for 
Search instead for 
Did you mean: 

update expression for only one row in the table

Former Member
0 Kudos
72

Hi,all

I need to update only one row in my table,

which sql expression can I use?

For example,I do the following:

sqlString = "UPDATE PivotTitle SET type = CASE WHEN (type = 2) THEN 1 WHEN (type = 3) THEN 2 WHEN (type = 4) THEN 3 ELSE type END"

The problem is that I have one row of each type(1,2,3) and many rows of

type 4,but I need to update only one row of type 4 to row of type 3.

Regards,

Michael

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Thanks for your replies

I solved my problem by myself.

Simply I added one more column to my table

with auto number and now I update only one row

of particular type by choosing the row with max(number).

Regards,

Michael

Former Member
0 Kudos

Michael,

Typically, "row" is restricted via defining primary key filter in query:


sqlString = "UPDATE PivotTitle SET type = CASE WHEN (type = 2) THEN 1 WHEN (type = 3) THEN 2 WHEN (type = 4) THEN 3 ELSE type END WHERE ID=?"
PreparedStatement pstmt = conn.prepareStatement(sqlString);
pstmt.setInt(1, 1234); // Key value is second parameter
pstmt.executeUpdate();

Valery Silaev

SaM Solutions

http://www.sam-solutions.net

abhijeet_mukkawar
Active Contributor
0 Kudos

Hi,

I think there is no specific sql expression for your requirement,

what you can do is make you selection for type4 more narrow, so that you will select the specific row and update that.

hope it helps

regards