我想在外部申请中写下 IF 条件。我需要返回多个列,所以我不想写子查询
SELECT name FROM v_users
OUTER APPLY
(
IF CAST(reg_date AS DATE)<CAST('03/25/2017' AS DATE)
SELECT gender,email,age,class FROM tb_register_old WHERE id=v_users.user_id;
ELSE
SELECT gender,email,age,class FROM tb_register_new WHERE id=v_users.user_id;
)s
答案 0 :(得分:4)
也许这个?
SELECT name FROM v_users
OUTER APPLY
(
SELECT gender,email,age,class
FROM tb_register_old
WHERE id=v_users.user_id and CAST(reg_date AS DATE)<CAST('03/25/2017' AS DATE)
UNION ALL
SELECT gender,email,age,class
FROM tb_register_new
WHERE id=v_users.user_id and CAST(reg_date AS DATE) >= CAST('03/25/2017' AS DATE)
)s