是否可以像IF
中那样在INSERT
内执行此类操作;
INSERT INTO @TABLE (ID, NAME, ADDRESS)
VALUES(
IF CONDITION (SELECT DATA)
ELSE (SELECT DATA)
)
答案 0 :(得分:4)
排序......
INSERT INTO @TABLE (ID, NAME, ADDRESS)
SELECT
CASE condition WHEN result then id else id2 end,
CASE condition WHEN result then name else name2 end,
...
或UNION
INSERT INTO @TABLE (ID, NAME, ADDRESS)
SELECT data FROM source WHERE condition
UNION
SELECT data FROM othersource WHERE NOT(condition)