SQL : a condition (IF-ELSE) in INSERT INTO

前端 未结 2 1138
无人及你
无人及你 2021-01-08 00:38

Is it possible ?

INSERT INTO tblPeople (id, group, company) VALUES (1, \'myGroup\', 
IF($company = \'\') BEGIN \'no company\' ELSE \'myCompany\         


        
2条回答
  •  别那么骄傲
    2021-01-08 01:22

    Probably not, but

    INSERT INTO tblPeople (id, [group], company) 
    Select 1, 'myGroup', Case When @Company = '' then 'no company' Else 'my company' End
    

    Should be a goer

提交回复
热议问题