Kewin Björk Nielsen Kewin Björk Nielsen - 4 months ago 8
SQL Question

how to check if a value is 1 and then change it to 0

how do i check if a value is

1.000000
in my column(that is called trashed numeric(18, 6)that are in fileitem table) then i update and if it is
1.000000
then i wan't to change it to
0.000000


my statement for updateing is

String query ="Update PS set ShelfNumber =' "+text2+ " ' from [file].[ItemPart] PS "+ " join [file].[Item] P on P.id = PS.id "+ " where P.ItemNumber = '"+text1 + "'";
PreparedStatement preparedStatement = con.prepareStatement(query);
preparedStatement.executeUpdate();


not sure if i have to make it as a stored procedure for being able to do it

Answer

I would expect an update to look something like this:

update t
    set trashed = 0
    where trashed = 1;