简体   繁体   English

Excel 公式帮助获得正确的语法

[英]Excel Formula help on getting the syntax right

Excel Version: 2016 Excel 版本:2016

I've asked the main question here, this is the extension of that question.我在这里问了主要问题,这是该问题的扩展。

Building SQL SELECT statement within EXCEL 在 EXCEL 内构建 SQL SELECT 语句在此处输入图像描述

I need to extend the logic for all the columns whenever there is a value in that in the sql "AND" clause as well.只要 sql“AND”子句中有值,我就需要扩展所有列的逻辑。

eg.例如。 AND TAB1.COLUMNA = TAB2.TCOLUMNA AND TAB1.COLUMNB = TAB2.COLUMNB and so on, only if there is a value in the DIM columns. AND TAB1.COLUMNA = TAB2.TCOLUMNA AND TAB1.COLUMNB = TAB2.COLUMNB依此类推,仅当 DIM 列中有值时。

I am not sure how to embed it dynamically using the SUBSTITUTE and TRIM functions.我不确定如何使用 SUBSTITUTE 和 TRIM 函数动态嵌入它。

Edit: Formula编辑:公式

="select * from (SELECT RET_ID,RET_NM,"&SUBSTITUTE(TRIM(C2&" "&D2&" "&E2&" "&F2)," ",",")&" FROM 
TABLEX ORDER BY "&SUBSTITUTE(TRIM(C2&" "&D2&" "&E2&" "&F2)," ",",")&") TAB1 FULL OUTER JOIN   (SELECT RET_ID,RET_NM,"&SUBSTITUTE(TRIM(C2&" "&D2&" "&E2&" "&F2)," ",",")&" FROM 
TABLEX ORDER BY "&SUBSTITUTE(TRIM(C2&" "&D2&" "&E2&" "&F2)," ",",")&") TAB2 ON TAB1.RET_ID = TAB2.RET_ID AND TAB1.RET_NM = TAB2.RET_NM  "

Solved, By this piece of code解决了,通过这段代码

"&IF(LEN(D2)>0,CONCATENATE("AND COALESCE(TAB1.",D2,",'')","="," COALESCE(TAB2.",D2,",'')"),"")&" 

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

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