A
A
Artem Lebedev2020-09-16 14:30:10
firebird
Artem Lebedev, 2020-09-16 14:30:10

How to edit a script?

Good day, for the task "write a query that allows you to increase by 1 all the values ​​of the VALUE field of the table TABLE_A, if for a given row in the table TABLE_B there is an identical row and increase by 2 if such a row does not exist." I made a script, but it gives an error when compiling. Please tell me how to fix.

UPDATE TABLE_A
SET VALUE = VALUE + CASE
                       WHEN EXISTS(SELECT * FROM TABLE_B WHERE TABLE_B.ID = TABLE_A.ID)
                       THEN 1
                       ELSE 2
                    END

error text: can't format message 13:896 -- message file C:\WINDOWS\firebird.msg not found.
Dynamic SQL Error.
SQL error code = -104.
Token unknown - line 2, column 5.
VALUE.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Lebedev, 2020-09-17
@lrik64

I figured it out, since there was a conflict of data types (in the first table INTEGER and in the second varchar ) I set INTEGER in two tables and the following script worked:

UPDATE TABLE_A
SET "VALUE" = "VALUE" + CASE
WHEN EXISTS(SELECT * FROM TABLE_B WHERE TABLE_B."VALUE" = TABLE_A."VALUE")
THEN + 1
ELSE + 2
END

Or it was necessary to be played with CAST.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question