简体   繁体   中英

How to write formula for cell in Excel?

I'm working on excel where I've few columns. I would like to make SQL insert operation from the records in sheet.

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 . 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).

The screenshot below shows the setup and results:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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