Is it possible to write an sql query that when executed in different conditions will write the data into different fields?

Is it possible to write an sql query that when executed in different conditions will write the data into different fields?
For example:
case 
when t1.abc = 'A' then insert t1.abc into t1 (letter) - if a single result is to insert into one field
when t1.abc = '1' then insert t1.abc into t1 (num) -- if a different result is to insert into another field
end

Is it possible to implement it in sql?
March 19th 20 at 08:36
3 answers
March 19th 20 at 08:38
Solution
The first is to create a query that returns data of different types in different columns, and already the results insertit.

insert into tb
select case when cond1 then 1 else null num,
 case when not cond1 then 'a' else null str
from ...


Here is an example in greater detail:
create table test_a(num number, str varchar2(100));

insert into test_a
with
 generator as
 (select case
 when dbms_random.value() > 0.5 then dbms_random.string('p', 10)
 else to_char(trunc(dbms_random.value(0, 100)))
 end str
 from dual
 connect by level <= 50),
 as classificator
 (select str, case
 when translate(str, chr(10)||'0123456789', chr(10)) is null then 'number'
 else 'string'
 end type
 from generator)
select case
 when type = 'number' then to_number(str)
 else null
 end num,
case
 when type = 'string' then str
 else null
 end str
 from classificator;
commit;

select * from test_a;
March 19th 20 at 08:40
Classic:

update table
set 
filed_n = case when condition1 then the value/expression else field_n end
filed_m = case when condition2 then value/expression else field_m end
where ....


With insert - in fact the same, only in case the negative branch will contain null
March 19th 20 at 08:42
True Oracle, but I think there should be a similar approach.
Here's a piece from my merge:
WHEN MATCHED THEN
UPDATE
SET DATE_E = CASE WHEN (DATE_B = MERGE_SUBQUERY.DATE_B$1)
THEN MERGE_SUBQUERY.DATE_E$1
ELSE DATE_E
END
It is possible to update both fields at different conditions on the value or on yourself.

Find more questions by tags SQL ServerTransact-SQLSQL