16

是否可以 ?

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

我想测试一个值,如果变量 $company 为空,我想写 no company。

4

2 回答 2

28

试试这个:

INSERT INTO tblPeople (id, group, company) 
select 1, 'myGroup', 
case 
  when @company is null or  @company = '' then 'no company' 
  else 'myCompany' 
END as  company
/*from tab --<-- optional*/
于 2013-01-08T12:44:33.583 回答
6

可能不是,但是

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

应该是路人

于 2013-01-08T12:45:10.113 回答