简体   繁体   English

如何在Excel中编写单元格的公式?

[英]How to write formula for cell in Excel?

I'm working on excel where I've few columns. 我正在研究Excel,而我的专栏却很少。 I would like to make SQL insert operation from the records in sheet. 我想从工作表中的记录进行SQL插入操作。

There are chances of cell to be empty and this is where I am unable to continue. 单元格有可能是空的,这是我无法继续的地方。 I need to check: 我需要检查:

if(cell is empty) 
   insert null 
else
   insert value

How can I implement it inside formula? 如何在公式中实现它?

=CONCONTENATE("INSERT INTO TABLE VALUES"("A1,if(A2="",NULL,"'","A2","'"))

correct me if anything wrong 如果有什么问题请纠正我

One example of a working function would be: 工作功能的一个示例是:

=CONCATENATE("INSERT INTO TABLE MyTable (Col1, Col2) VALUES ('", A2, "', ", IF(ISBLANK(B2), "NULL", CONCATENATE("'", B2, "'")), ")")

This assumes that you are inserting two values from the same Excel row, adds quotes around values to allow you to insert text strings, and then replaces any blank values with NULL . 假定您要从同一Excel行中插入两个值,并在值周围添加引号以允许您插入文本字符串,然后将所有空白值替换为NULL The IF() statement contains its own CONCATENATE() to add quotes around the value if it exists (you wouldn't want quotes around the NULL value). IF()语句包含其自己的CONCATENATE()用于在值存在的情况下添加引号(您不希望在NULL值周围使用引号)。

The screenshot below shows the setup and results: 下面的屏幕快照显示了设置和结果:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM