在EXCEL中构建SQL SELECT语句 [英] Building SQL SELECT statement within EXCEL
问题描述
我正在尝试在excel中构建SQL语句.
I am trying to build SQL statements within excel.
示例:
我正在尝试构建sql语句,但只想在DIM列中有值时才添加该列.因此,在SQL中执行时,SQL看起来很整洁,没有任何语法错误.
I am trying to build sql statement, but wanted to only add the column when there is a value in the DIM columns. So the SQL looks neat without any syntax error when executed in SQL.
在这里,如何消除关键字"from"之前的多余逗号?
Here how can I eliminate the extra commas before the "from" keyword?
使用它来生成那些语句.
Used this to generate those statements.
="SELECT RET_ID,RET_NM, "&C2&","&D2&","&E2&","&F2&" FROMTABLEX"
推荐答案
这是一种适用于所有版本Excel的方法
Here's an approach which shall work for all versions of Excel
="SELECT RET_ID,RET_NM,"& SUBSTITUTE(TRIM(C2&"& D2&"& E2&"& F2),",,")&"FROMTABLEX"
您可以在 TRIM()
中添加任意数量的列.
You can add any number of columns inside TRIM()
.
这篇关于在EXCEL中构建SQL SELECT语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!