在EXCEL中构建SQL SELECT语句 [英] Building SQL SELECT statement within EXCEL

查看:132
本文介绍了在EXCEL中构建SQL SELECT语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆