如何在Excel公式中显示已解析的名称

时间:2015-04-10 16:28:27

标签: excel

我是否有一种简单的方法可以将以下内容(如果只有一秒钟)转换为真正的SQL?:

=IFERROR(eagle("SELECT SUM("&selectedmonth&")/1000, ("& ytdformula & ")/1000 AS YTD, sum(Budget)*"&sMonthIndex&"/12000
             FROM ["&environment&"].[dbo].[SD_"&selectedyear&"_flat" & IF(selectedCurrency="USD","","_EUR") &"]
             WHERE 1=1
             "&IF(selectedDepartment="All",""," AND department = '"&selectedDepartment&"'")&" 
             "&IF(selectedproduct="All",""," AND product = '"&selectedproduct&"'")&"      
             "&IF(AND(getMacro=FALSE,getRatesNSU=FALSE),
               IF(selecteddivision="All",""," AND division='"&selecteddivision&"'"),
               IF(getMacro=TRUE," AND (division = 'Commodities' OR division = 'FX Products' OR division = 'Rate Products')"," AND (division = 'Rate Products' OR product = 'IB Non-Strategic Unit')"))&"
             "&IF(exclSMG=FALSE,""," AND Division <> 'Systematic Market Making'")&"
             "&IF(selectedsubdivision="All",""," AND subdivision = '"&selectedsubdivision&"'")&"
             "&IF(selectedcluster="All",""," AND cluster = '"&selectedcluster&"'")&"    
             "&IF(selectedregion="All",""," AND region = '"&selectedregion&"'")&"
             "&IF(selectedBiz="All",""," AND business_unit IN "&selectedBiz),connectionString),0)

1 个答案:

答案 0 :(得分:0)

将单词stop放在此行代码前面,然后将以下内容粘贴到VBA立即窗口中,前面有一个问号。

?"SELECT SUM("&selectedmonth&")/1000, ("& ytdformula & ")/1000 AS YTD, sum(Budget)*"&sMonthIndex&"/12000
         FROM ["&environment&"].[dbo].[SD_"&selectedyear&"_flat" & IF(selectedCurrency="USD","","_EUR") &"]
         WHERE 1=1
         "&IF(selectedDepartment="All",""," AND department = '"&selectedDepartment&"'")&" 
         "&IF(selectedproduct="All",""," AND product = '"&selectedproduct&"'")&"      
         "&IF(AND(getMacro=FALSE,getRatesNSU=FALSE),
           IF(selecteddivision="All",""," AND division='"&selecteddivision&"'"),
           IF(getMacro=TRUE," AND (division = 'Commodities' OR division = 'FX Products' OR division = 'Rate Products')"," AND (division = 'Rate Products' OR product = 'IB Non-Strategic Unit')"))&"
         "&IF(exclSMG=FALSE,""," AND Division <> 'Systematic Market Making'")&"
         "&IF(selectedsubdivision="All",""," AND subdivision = '"&selectedsubdivision&"'")&"
         "&IF(selectedcluster="All",""," AND cluster = '"&selectedcluster&"'")&"    
         "&IF(selectedregion="All",""," AND region = '"&selectedregion&"'")&"
         "&IF(selectedBiz="All",""," AND business_unit IN "&selectedBiz),connectionString),0)

立即窗口将所有变量和文字连接到它试图执行的SQL字符串中。

如果SQL中存在错误,您应该能够将SQL复制到QBE编辑器中以获取编译器无法协调的错误消息。