我正在尝试使用插入
中的case
创建一些逻辑
这是我正在使用的代码,但
elseif ( exists(select id from transactions where tel = last_inserted_number && secure_using_payslip IS NULL)) then
update transactions set secure_using_payslip=last_inserted_message where
tel=last_inserted_number;
insert into messageout(messagetext, messageto)
values("you choose not to secure with payslip.", last_inserted_number),(case when last_inserted_message = 'no');
insert into messageout(messagetext, messageto)
values("you choose to secure with payslip.", last_inserted_number),(case when last_inserted_message = 'yes');
insert into messageout(messagetext, messageto)
values("Are you formally employed or self employed?.", last_inserted_number);
代码失败了。我该如何使用案例?。
答案 0 :(得分:1)
将CASE
表达式放入值中。
INSERT INTO messageout (messagetext, messageto)
VALUES (CASE last_inserted_message
WHEN 'no' THEN "you choose not to secure with payslip."
WHEN 'yes' THEN "you choose to secure with payslip."
ELSE "Invalid choice."
END, last_inserted_number);