2

是否可以做一些事情,比如在这样的情况下IF发表声明INSERT

INSERT INTO @TABLE (ID, NAME, ADDRESS)
VALUES(
    IF CONDITION (SELECT DATA)
    ELSE (SELECT DATA)
)
4

1 回答 1

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)
于 2012-08-20T10:25:37.253 回答